I'll Do It Tomorrow

No attempts yetTime limit2sMemory limit256 MB

Problem

Ugh, I really don't want to do my assignments. I don't want to do anything at all.

There are nn assignments listed on my desk. Each assignment ii takes did_i days to finish and must be submitted within tit_i days from today. In other words, if today is day 0, assignment ii must be completed before the end of day tit_i. Once you start an assignment you must work on it continuously until it is done, without any break, and you can work on only one assignment at a time.

Today (day 0) I've decided to do nothing. On top of that, starting from tomorrow I want to keep doing nothing and relax for as long as possible.

Assuming every assignment can be finished by its deadline, find the maximum number of consecutive days, starting from tomorrow (day 1), that I can relax and do nothing.

Input

The first line contains an integer nn (1n1061 \le n \le 10^6), the number of assignments.

Each of the next nn lines contains two integers did_i and tit_i (1di,ti1091 \le d_i, t_i \le 10^9), separated by a space, describing one assignment. Today is day 0.

It is guaranteed that there always exists a way to finish every assignment on time even if you do nothing today.

Output

Print, on a single line, the maximum number of consecutive days you can relax starting from tomorrow (day 1). For example, if the answer is 0 you must start an assignment tomorrow, and if it is 1 you must start an assignment the day after tomorrow.

Hint

For the first example, you relax on days 1–5, work on the first assignment on days 6–7, the third assignment on days 8–10, relax on days 11–12, and work on the second assignment on day 13.