#CCBCHBAHAI0000083. Giá trị xuất hiện đúng một lần - nhỏ nhất (Smallest Value Appearing Exactly Once)

    ID: 1001 Loại: Thông thường 2000ms 256MiB Tried: 0 Đã chấp nhận: 0 Độ khó: 1 Đăng bởi: Nhãn>Programming language basicsStatic arraysIteration techniquesImplementation techniquesWorking with numbers

Giá trị xuất hiện đúng một lần - nhỏ nhất (Smallest Value Appearing Exactly Once)

Smallest Value Appearing Exactly Once

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem

Given a0,a1,…,an−1a_0,a_1,\ldots,a_{n-1} with 0≤ai≤10000\le a_i\le1000, define

f(v)=∣{i∣0≤i<n, ai=v}∣f(v)=|\{i\mid0\le i<n,\ a_i=v\}|

and U={v∈[0,1000]∣f(v)=1}U=\{v\in[0,1000]\mid f(v)=1\}. Print min⁡U\min U if UU is nonempty; otherwise print -1.

Input

The first line contains nn. The second line contains nn integers in [0,1000][0,1000].

Output

Print the smallest value appearing exactly once, or -1 if none exists.

Subtask

Subtask 1 (20 points): 1≤n≤101\le n\le 10, 0≤ai≤10000\le a_i\le 1000.

Subtask 2 (30 points): 1≤n≤50001\le n\le 5000, 0≤ai≤10000\le a_i\le 1000.

Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le 2\cdot 10^5, 0≤ai≤10000\le a_i\le 1000.

Example

Input

8
5 2 9 2 7 5 4 9

Output

4

Explanation

The output follows directly from the mathematical definition above.