SDE Path

Second Largest Element Without Sorting

Easy

Second Largest Element Without Sorting

Find the second largest distinct element in an array without sorting it.

Input format

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

Output format

Print the second largest distinct element. If it does not exist (all elements equal), print -1.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
5
12 35 1 10 34
Expected output
34
Example 2
Input
3
10 10 10
Expected output
-1