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) { int max = 0; int value = 0; HashMap myMap = new HashMap<>(); 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(); if(myMap.containsKey(types[types_i])){ myMap.put(types[types_i], myMap.get(types[types_i]) + 1); } else{ myMap.put(types[types_i],1); } } Iterator it = myMap.entrySet().iterator(); while(it.hasNext()){ Map.Entry pair = (Map.Entry)it.next(); if(((int)pair.getValue()) > max){ max =(int) pair.getValue(); value =(int) pair.getKey(); } } System.out.println(value); // your code goes here } }