View as PDF

Points: 15 (partial)
Time limit: 5.0s
Memory limit: 256M

Problem types

Larry often goes to Olympiads to better his academic abilities. Unfortunately many of their classes overlap, and he can't take multiple classes at the same time.

There are classes that Larry wants to take, each of which are offered on two separate days and . Larry cannot attend multiple classes on the same day.

Can Larry attend all classes? If so, what is the earliest he can do so?

#### Input Specification

The first line contains an integer .

The next lines contain two integers .

#### Output Specification

On one line you are to output the earliest day that Larry can have taken all the classes, or -1 if Larry is unable to take all the classes.

#### Sample Input

3
10 40
40 80
10 80

#### Sample Output

80