#C11276. Find the Special Number

    ID: 40574 Type: Default 1000ms 256MiB

Find the Special Number

Find the Special Number

You are given a sequence of integers. Your task is to identify and print the first integer that occurs exactly twice in the sequence. If no such integer exists, print -1.

This problem can be mathematically expressed as follows: Given a sequence of integers \(a_1, a_2, \dots, a_n\), find the element \(x\) such that its frequency \(\#(x)=2\), where \(\#(x)\) denotes the number of times \(x\) appears in the sequence. If there are multiple candidates that satisfy the condition, output the one encountered first from left to right.

inputFormat

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

  1. The first line contains a single integer n representing the number of elements in the sequence.
  2. The second line contains n space-separated integers.

outputFormat

Print a single integer to stdout which is the first element that appears exactly twice. If no such element exists, print -1.

## sample
6
4 1 5 3 5 2
5