import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] types = new int[n]; for(int types_i=0; types_i < n; types_i++){ types[types_i] = in.nextInt(); } // your code goes here Map Count = new HashMap<>(); Map result = new HashMap<>(); for (int x : types) { Integer count = Count.get(x); if (count == null) { Count.put(x, 1); } else { Count.put(x, ++count); } } Set> entrySet = Count.entrySet(); for (Entry entry : entrySet) { if (entry.getValue() > 1) { result.put(entry.getKey(), entry.getValue()); } } int max=(Collections.max(result.values())); Set keys = new HashSet(); for (Entry entry : result.entrySet()) { if (Objects.equals(max, entry.getValue())) { keys.add(entry.getKey()); } } Object obj = Collections.min(keys); System.out.println(obj); } }