400788: GYM100247 J The Best Statement

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. The Best Statementtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Team Samara SAU Teddy Bears is making the statement for one problem for the qualification round. Pavel generates the variants of the statement one after another while Alexey for each of these variants says whether he approves the variant or not. The process will be finished just after Alexey will approve one variant of the statement. Nikita does not formally involved in this process but he's rooting for the statement with all his heart.

Nikita understood the principle: for each Pavel's statement there are Alexey's and Nikita's grades of its quality. Nikita figured out Pavel's behavior and guessed that Pavel will generate n statements so that Alexey's grades for them will be ai and Nikita's ones — bi. Alexey will approve the statement if he evaluates it greater than or equal to k.

Before all the process, Nikita can predetermine Alexey's mood and set an arbitrary value to k. Then this value will be fixed for the rest of process. Of course, Nikita should select the value of k so that at least one of the variants of the statement will be approved by Alexey. Nikita wants to maximize his own grade of the approved statement. What is the best result he can achieve?

Input

The first line contains a single integer n (1 ≤ n ≤ 200000) — the number of the variants of the statement.

Then n lines follow. Each of them contains two integers separated by space: ai and bi (1 ≤ ai, bi ≤ 109) — grades of Alexey and Nikita for the i-th statement, correspondingly.

Output

Output a single integer — the maximal Nikita's grade of the statement he can achieve.

ExamplesInput
3
3 3
4 6
2 5
Output
6
Input
3
2 5
4 3
3 6
Output
5

加入题单

算法标签: