#!/bin/ruby

n = gets.strip.to_i
types = gets.strip
types = types.split(' ').map(&:to_i)
# your code goes here

counts = Hash.new(0)
types.each { |t| counts[t] += 1 }
max_val = 0
max_key = 0
counts.each do |k, v|
    if v > max_val || (v == max_val && k < max_key)
        max_val = v
        max_key = k
    end
    
end

puts max_key