#!/bin/python import sys n = int(raw_input().strip()) types = map(int, raw_input().strip().split(' ')) # your code goes here maxtype = float('inf') maxnum = 0 count = {} for num in types: if num in count: count[num] += 1 if (count[num] > maxnum): maxnum = count[num] maxtype = num elif (count[num] == maxnum) and (num < maxtype): maxnum = count[num] maxtype = num else: count[num] = 1 if (count[num] > maxnum): maxnum = count[num] maxtype = num elif (count[num] == maxnum) and (num < maxtype): maxnum = count[num] maxtype = num print maxtype