#!/bin/python3 import sys n = int(input().strip()) types = list(map(int, input().strip().split(' '))) # your code goes here typdic={} mctyp=[] tmpmax=0 for typ in types: if typ in typdic: typdic[typ]+=1 else: typdic[typ]=1 if typdic[typ]==tmpmax: mctyp.append(typ) elif typdic[typ]>tmpmax: mctyp=[typ] tmpmax=typdic[typ] print(min(mctyp))