Numbers

Time limit1sMemory limit128 MB

Summary
Given N positive integers, find the value with the highest frequency, breaking ties by choosing the smallest value.
Level

Easy3 of 10

Topics
Array, Hash map, Sorting
Solved
No attempts yet

Problem

You are given NN positive integers X1,X2,…,XNX_1, X_2, \ldots, X_N. Write a program that finds the smallest value that appears at least as many times as every other number in the sequence (that is, a value whose frequency is maximal).

In other words, among all values that share the maximum frequency, output the smallest one.

Input

The first line contains a single integer NN. Each of the next NN lines contains one integer XiX_i (for i=1,2,…,Ni = 1, 2, \ldots, N).

Output

Print a single integer: the smallest value that appears at least as many times as any other number. Equivalently, if several values share the maximum frequency, print the smallest of them.

Constraints

  • 2≤N≤10002 \le N \le 1000
  • 1≤Xi≤100001 \le X_i \le 10000

Examples1

  1. Example 1

    Input
    10
    1
    2
    3
    4
    5
    3
    2
    3
    1
    2
    
    Expected output
    2