Second largest number

Read N integers and print the second largest distinct value. If it does not exist, print -1.

Reported in: Infosys (2022–25), Accenture, Cognizant GenC, LTIMindtree (memory-based)

Input

First line: N. Second line: N integers.

Output

The second largest distinct value, or -1.

Constraints

1 ≤ N ≤ 10^5; values fit in a 32-bit integer.

Example 1

Input:
5
4 9 2 9 7

Output:
7

Example 2

Input:
3
5 5 5

Output:
-1

Hint: Track the largest and second largest in one pass, skipping values equal to the largest.

All coding practice