Passengers

No attempts yetTime limit1sMemory limit1024 MB

Problem

Every weekend a plane flies from Bitland to Vilnius. The passengers on this plane are very demanding and constantly trouble the crew: they keep asking for tea, a pillow, and so on.

While the crew tries to satisfy every request, the plane sometimes has to be kept circling above Vilnius before it can land! Naturally, the Bitland airline dislikes this, so from now on it asks its passengers to submit in advance a list of what they will request and when.

Given this list, find the minimum amount of time the flight attendant needs to fulfill all requests, assuming she plans her time optimally.

You also know that:

  • Moving between two adjacent rows takes 1 minute.
  • The flight attendant fulfills a request very quickly, so fulfilling a request is assumed to take no time (0 minutes).
  • The flight attendant starts the flight standing at the first row.
  • The flight attendant must finish the flight standing at the first row.

Input

The first line contains the number of requests NN.

Each of the next NN lines contains two integers aia_i and bib_i describing one passenger request. Here aia_i is the number of the row where the passenger sits, and bib_i is the earliest time at which the ii-th request is submitted (it may be fulfilled at that time or at any later time).

Output

Print a single integer — the minimum number of minutes needed for the flight attendant to fulfill all requests and return to the first row.

Constraints

  • 1N1051 \le N \le 10^5
  • 1ai,bi1061 \le a_i, b_i \le 10^6