Postering

No attempts yetTime limit1sMemory limit128 MB

Problem

All the buildings in the eastern district of Byteburg were built in the old style: they stand right next to one another with no gaps in between. Together they form a very long chain of buildings of varying heights, stretching from east to west.

The mayor of Byteburg, Byteasar, has decided to cover the northern face of the chain with posters. He wonders about the smallest number of posters that suffices to cover the whole northern face. Each poster is a rectangle with vertical and horizontal sides. Posters may not overlap, but they may touch, that is, share points along their edges. Every poster must lie flush against the walls of some buildings, and the entire surface of the northern face must be covered.

Write a program that:

  • reads the description of the buildings from standard input,
  • determines the minimum number of posters needed to cover their northern faces completely,
  • writes the result to standard output.

Input

The first line contains one integer nn (1n2500001 \le n \le 250\,000), the number of buildings in the chain. Each of the next nn lines contains two integers did_i and wiw_i (1di,wi1091 \le d_i, w_i \le 10^9), separated by a single space, giving respectively the width and the height of the ii-th building in the row.

Output

Output a single integer: the minimum number of rectangular posters that suffice to cover the northern faces of the buildings.

Hint

The figures below illustrate an example. The first shows the northern face of a chain of buildings, and the second shows one way to cover that face with four posters.