Elevator

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

You have a very important job: you are responsible for an elevator in the new skyscraper.

There are nn persons who will come to the underground parking located on floor 00 and wait for an elevator to bring them to some upper floor. Formally, ii-th person comes to the elevator at moment t_it\_i and wants to reach floor a_ia\_i. The elevator has infinite capacity; that is, there is no limit on the number of people using the elevator at any moment. All numbers t_it\_i are distinct. Passengers always enter the elevator as long as it is at floor 00

The elevator uses the following algorithm: it stays open on floor 00 until you send it to deliver passengers, then it moves to the highest floor it needs (the maximum a_ia\_i among all passengers who are currently in the elevator), distributing the passengers in the process, and returns to the parking. The elevator spends 11 unit of time to move to the next floor (or to the previous floor). The time spent for opening and closing the doors of the elevator, as well as for the passengers entering and leaving the elevator, is negligible. At moment 00, the elevator is at floor 00.

You want to minimize the moment of time when the elevator will return to floor 00 after delivering everyone.

입력

The input contains one or more test cases.

The first line of each test case contains one integer nn: the number of passengers (1n21051 \le n \le 2 \cdot 10^5).

Each of the following nn lines contains two space-separated integers t_it\_i and a_ia\_i: the moment of time when ii-th passenger comes to the elevator, and the destination floor of ii-th passenger (1t_i,a_i1091 \le t\_i, a\_i \le 10^9).

All t_it\_i in one test case are distinct, passengers appear in input in ascending order of t_it\_i.

The sum of the values of nn over all test cases does not exceed 21052 \cdot 10^5. The test cases just follow one another without any special separators.

출력

For each test case, print one integer: the minimum possible moment of time when the elevator will return after delivering all passengers.