시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB2791148441.584%

문제

택희는 인터넷에서 노래를 다운받으려고 한다. 노래는 여러 조각으로 나누어져 있고, 정해진 순서대로 다운받아야 한다. 택희는 각 조각의 노래 길이와 다운로드 길이를 알고 있다.

택희는 노래를 모두 다운받기 전에 들으려고 한다. 음악이 중간에 끊여지면 분위기를 망치기 때문에, 한 번 듣기 시작하면 노래는 멈추지 않고 끝까지 재생해야 한다. 각 조각을 들으려면 그 조각을 모두 다운로드 해야 들을 수 있다.

택희가 음악을 끊김없이 들으려면, 다운로드 시작한지 몇 초 후에 들으면, 끊김 없이 노래를 들을 수 있는지 구하는 프로그램을 작성하시오. 

입력

첫째 줄에 조각의 수 N이 주어진다. (1 ≤ N ≤ 100,000)

다음 N개의 줄에는 노래의 길이 D와 다운로드하는데 걸리는 시간 V가 주어진다. (1 ≤ D,V ≤ 1000)

출력

첫째 줄에, 다운로드 시작하고 몇 초 후에 노래를 듣기 시작하면, 끊김 없이 들을 수 있는지 출력한다. 그러한 시간이 여러개라면, 가장 빠른 것을 출력한다.

예제 입력 1

4
2 1
1 5
3 3
2 4

예제 출력 1

7

예제 입력 2

5
1 1
1 2
3 1
2 1
3 3

예제 출력 2

2

예제 입력 3

7
2 1
2 4
1 2
2 1
3 2
3 1
1 3

예제 출력 3

3
W3sicHJvYmxlbV9pZCI6IjMyMTYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWIyZTRcdWM2YjRcdWI4NWNcdWI0ZGMiLCJkZXNjcmlwdGlvbiI6IjxwPlx1ZDBkZFx1ZDc2Y1x1YjI5NCBcdWM3NzhcdWQxMzBcdWIxMzdcdWM1ZDBcdWMxMWMgXHViMTc4XHViNzk4XHViOTdjIFx1YjJlNFx1YzZiNFx1YmMxYlx1YzczY1x1YjgyNFx1YWNlMCBcdWQ1NWNcdWIyZTQuIFx1YjE3OFx1Yjc5OFx1YjI5NCBcdWM1ZWNcdWI3ZWMgXHVjODc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