import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int mostFrequent(int... ary) { Map m = new HashMap(); for (int a : ary) { Integer freq = m.get(a); m.put(a, (freq == null) ? 1 : freq + 1); } int max = -1; int mostFrequent = -1; for (Map.Entry e : m.entrySet()) { if (e.getValue() > max) { mostFrequent = e.getKey(); max = e.getValue(); } } return mostFrequent; } 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 System.out.println(mostFrequent(types)); } }