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); Map m=new HashMap(); int mostOccur=0; int times=0; 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(m.get(types[types_i])==null){ m.put(types[types_i],1); if(m.get(types[types_i])>times){ times=m.get(types[types_i]); mostOccur= types[types_i]; } } else{ m.put(types[types_i],m.get(types[types_i])+1); if(m.get(types[types_i])>times || (m.get(types[types_i])==times && mostOccur > types[types_i])){ times=m.get(types[types_i]); mostOccur= types[types_i];} } } System.out.println(mostOccur); } }