import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static int mode(int[] nums){ int bestType = -1; //Most common type thus far int bestCount = 0; //Cardinality of most common type HashMap counts = new HashMap(); //Tracks counts for (int i=0; i < nums.length; i++) { int type = nums[i]; //Update counts if (counts.containsKey(type)) { int count = counts.get(type) + 1; counts.put(type,count); } else { counts.put(type, 1); } //Update most common int count = counts.get(type); if (count > bestCount) { bestType = type; bestCount = count; } else if ((count == bestCount) && (type < bestType)) { bestType = type; bestCount = count; } } return bestType; } 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(mode(types)); } }