#!/bin/python3 import sys import itertools n = int(input().strip()) types = list(map(int, input().strip().split(' '))) # your code goes here unique=[] repeat=[] amountE=[] back = [] for i in types: if i not in unique: unique.append(i) for i in unique: a = 0 for j in types: if j == i: a = a + 1 amountE.append(a) check = [i for i, x in enumerate(amountE) if amountE.count(x) > 1] for i in range(len(amountE)): if amountE[i] == max(amountE): repeat.append(i) if len(repeat) == 1: ind = amountE.index(max(amountE)) print(unique[ind]) elif len(repeat) > 1: for i in repeat: back.append(unique[i]) print(min(back))