E - Refrigerator

The company you work in produces some chemical substances. They own one big refrigerator in which they can store all the substances.
But the company didn't predict that each substance must be stored in a specified range of temperatures and the refrigerator can be set only to one fixed temperature. Hence many substances will get spoilt and become unusable.

To minimize losses the company asked you to write a program which calclulates temperature in which as many substances can be kept as it is possible. If there is more than one such temperature your program is supoused to output the greates one.

Input

Input consists of several test cases. Each of them starts with a number of substances N (1<=N<=50.000), followed by N pairs of integers Li and Ri (Li<=Ri), which mean that substance i can be stored only in the range of temperatures from Li to Ri including these values (i=1..N). Input ends with a specific test case in which N is equal to 0 - do not process this case!

Output

For each test case output a line containg temperature the refrigerator should be set to.

Sample Input

1
0 5
2
1 3
3 5
3
-200 200
-100 100
0 0
0

Sample Output

5
3
0