#CCBCHBAHAI0000082. Giá trị lặp đầu tiên - miền 0..1000 (First Repeated Value in the Range 0..1000)

    ID: 1000 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ị lặp đầu tiên - miền 0..1000 (First Repeated Value in the Range 0..1000)

First Repeated Value in the Range 0..1000

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, scan left to right. Let

p=min⁡{i∣∃j<i: aj=ai}p=\min\{i\mid\exists j<i:\ a_j=a_i\}

if such an index exists. Print apa_p, the first value encountered for the second time. If no value repeats, print -1.

Input

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

Output

Print the first repeated value, or -1 if there is none.

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

7
4 1 7 4 1 9 7

Output

4

Explanation

The output follows directly from the mathematical definition above.