Find the First Unique ElementMedium

Find the First Unique Element

MediumPractice library · +20 XPhash maparraysfrequency

Given an array of N integers, find the first integer that appears exactly once. If no such integer exists, return -1. The order of elements in the input array matters.

Input

The first line contains an integer N. The second line contains N space-separated integers.

Output

Print the first integer that appears exactly once, or -1 if none exists.

Constraints

1 <= N <= 200000. Each integer will be between -10^9 and 10^9.

Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests

Example 1

Input
5
1 2 3 2 1
Output
3

3 is the first element that appears only once.

Example 2

Input
3
5 5 5
Output
-1

No element appears exactly once, so output -1.

Hints