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]; HashMap h = new HashMap(); for(int types_i=0; types_i < n; types_i++){ types[types_i] = in.nextInt(); if(h.containsKey(types[types_i])){ h.put(types[types_i], h.get(types[types_i])+1); }else { h.put(types[types_i], 1); } } List > tl = new ArrayList>(h.entrySet()); Comparator> mycom = new Comparator>(){ @Override public int compare(Map.Entry m1,Map.Entry m2){ int r = m2.getValue().compareTo(m1.getValue()); int r2 =m1.getKey().compareTo(m2.getKey()); if(r == 0){ return r2; }else { return r; } } }; Collections.sort(tl,mycom); for (Map.Entry entry : tl) { } System.out.println(tl.get(0).getKey()); } }