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 hm=new HashMap(); for(int types_i=0; types_i < n; types_i++){ types[types_i] = in.nextInt(); if (hm.containsKey(types[types_i])){ hm.put(types[types_i], hm.get(types[types_i]) + 1); }else{ hm.put(types[types_i],1); } } // your code goes here ArrayList ar = new ArrayList(); for(Map.Entry m:hm.entrySet()){ //System.out.println(m.getKey()+" "+m.getValue()); tuple a = new tuple(Integer.parseInt(m.getKey().toString()) ,Integer.parseInt(m.getValue().toString())); ar.add(a); } Collections.sort(ar, new Comparator() { @Override public int compare(tuple o1, tuple o2) { if (o1.getValue() > o2.getValue()) { return -1; } else if (o1.getValue() < o2.getValue()) { return 1; } else { return 0; } } }); int highFreqKey = ar.get(0).getKey(); int highFreqVal = ar.get(0).getValue(); for(int i=0; ihighFreqVal) break; } System.out.print(highFreqKey); } } class tuple{ int key; int value; tuple(int key,int value){ this.key = key; this.value = value; } int getKey(){ return this.key; } int getValue(){ return this.value; } }