Joke with Turtles

No attempts yetTime limit2sMemory limit128 MB

Problem

There is a famous riddle-joke for children:

Three turtles are crawling along a road. The first turtle says: "There are two turtles ahead of me." The second turtle says: "There are two turtles behind me." The third turtle says: "There are two turtles ahead of me and two turtles behind me." How can this be?

The answer is: the third turtle is lying!

In this problem, nn turtles are crawling along a road. Several turtles may crawl together in a group at the same position, so that turtles in the same group see none of their group members either ahead or behind them. Each turtle makes a statement of the form: "There are aia_i turtles ahead of me and bib_i turtles behind me." Find the minimum possible number of turtles that are lying.

Formally, turtle ii has a coordinate xix_i, and different turtles may share the same coordinate. Turtle ii tells the truth if and only if the number of turtles jj with xj>xix_j > x_i is exactly aia_i and the number of turtles jj with xj<xix_j < x_i is exactly bib_i; otherwise turtle ii is lying. You may choose the coordinates freely, and you must report the minimum number of turtles that must be lying, taken over all arrangements (equivalently, nn minus the maximum number that can simultaneously tell the truth).

Input

The first line contains an integer nn (1n10001 \le n \le 1000). Each of the next nn lines contains two integers aia_i and bib_i (0ai,bi10000 \le a_i, b_i \le 1000) describing the statement of turtle ii for ii from 11 to nn.

Output

Print a single integer mm: the minimum number of turtles that must be lying.