zidarska | 프로그래밍의 벗 PivotOJ
PivotOJ

zidarska

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2004 National Competition #2 - JuniorsBOJ 3216

문제

Mirko wants to download his favorite song from the internet. 

The song is divided into segments that must be downloaded in fixed order. We know the length and download time of each segment (both are expressed in seconds). 

If it's possible, he wants to start listening to his song as soon as possible, even before it's downloaded, with no interruptions (no waiting for some segment to be downloaded in the middle of the song). He can start listening to a segment only after it has been completely downloaded. 

Write a program that will determine the minimal number of seconds (from the moment that download starts) after which Mirko can start listening. 

입력

In the first line there is an integer N, 1 ≤ N ≤ 100,000, number of segments. 

In each of the following N lines, there are two integers, D and V, 1 ≤ D,V ≤ 1000. These numbers represent segments in the order they have to be downloaded. D is length, V is download time. 

출력

In the first and only line write the number of seconds from the text. 

예제

예제 1

입력
4
2 1
1 5
3 3
2 4
출력
7

예제 2

입력
5
1 1
1 2
3 1
2 1
3 3
출력
2

예제 3

입력
7
2 1
2 4
1 2
2 1
3 2
3 1
1 3
출력
3
코드를 제출하려면 로그인하세요.