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(); } System.out.println(getMostCommon(types)); } public static int getMostCommon(int[] arr) { SortedMap typeCounts = new TreeMap<>(); for (int i = 0; i < arr.length; i++) { if (typeCounts.containsKey(arr[i])) { int oldCount = typeCounts.get(arr[i]); typeCounts.put(arr[i], oldCount+1); } else { typeCounts.put(arr[i], 1); } } int max = -1; int maxKey = -1; for (Integer typeKey : typeCounts.keySet()) { Integer keyValue = typeCounts.get(typeKey); if (keyValue > max) { max = keyValue; maxKey = typeKey; } else if (keyValue == max) { if (maxKey > typeKey) { maxKey = typeKey; } } } return maxKey; } }