import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; 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 m = new HashMap(); for (Integer i: types){ Integer freq = m.get(i); m.put(i, (freq==null)? 1 : freq+1); } Integer keyToMax = 0; Integer maxValue = 0; for(Map.Entry entry: m.entrySet()){ if (maxValue < entry.getValue()){ maxValue = entry.getValue(); keyToMax = entry.getKey(); } else if (maxValue == entry.getKey()){ keyToMax = keyToMax < entry.getKey()? keyToMax : entry.getKey(); } } System.out.print(keyToMax); } }