#K92297. Highest Unique Grade

    ID: 38166 Type: Default 1000ms 256MiB

Highest Unique Grade

Highest Unique Grade

You are given the records of n students. Each record contains a unique student ID and his/her grade. Your task is to determine the highest grade that appears exactly once among all students. If no grade is unique, output -1.

In mathematical notation, let (G = {g_1, g_2, \ldots, g_n}) be the set of grades associated with the students. We define a grade (g) as unique if and only if the frequency (f(g) = 1). The goal is to find (\max{g \in G \mid f(g) = 1}), or output -1 if such a grade does not exist.

inputFormat

The first line contains an integer (n) representing the number of students. Each of the next (n) lines contains two space-separated integers representing the student ID and the grade respectively.

outputFormat

Output a single integer which is the highest unique grade among the students, or -1 if no unique grade exists.## sample

5
1 95
2 85
3 95
4 75
5 70
85