#K79342. Lowest Unique Integer

    ID: 35287 Type: Default 1000ms 256MiB

Lowest Unique Integer

Lowest Unique Integer

Given a list of integers, find and output the smallest integer that occurs exactly once in the list. If there is no integer that occurs exactly once, output -1.

Note: The solution should read input from standard input (stdin) and output the result to standard output (stdout).

The problem is defined as follows:

Let \(A = [a_1, a_2, \ldots, a_n]\) be a list of integers. We say an integer \(x\) is unique if it appears exactly once in \(A\). Find the smallest such unique integer, i.e., compute \[ \min\{ x : \text{frequency}(x)=1 \} \] If no such \(x\) exists, output \(-1\).

inputFormat

The input is read from standard input (stdin) and has the following format:

<n>
<a1 a2 ... an>

where:

  • n is an integer representing the number of elements in the list.
  • a1, a2, ..., an are the list of integers separated by spaces. If n = 0, the list is considered empty.

outputFormat

Output the smallest unique integer from the list to standard output (stdout). If there is no unique integer, output -1.

## sample
7
1 2 2 3 4 4 5
1