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 HashMap hMap = new HashMap<>(); for(int i =0; i< n ; i++){ if(hMap.get(types[i]) != null){ hMap.put(types[i], hMap.get(types[i]) + 1); } else{ hMap.put(types[i], 1); } // System.out.println("Done: "+types[i] + " Value: " + hMap.get(types[i])); } // Find the duplicates. Map.Entry max = null; for(Map.Entry e : hMap.entrySet()){ if(max == null) max = e; else if(e.getValue() == max.getValue()){ max = (max.getKey() < e.getKey()) ? max:e; } else if(e.getValue() > max.getValue()){ max = e; } } System.out.println(max.getKey()); } }