The Bale Tower

No attempts yetTime limit1sMemory limit128 MB

Problem

The cows have invented a new game. One cow brings out a set of $N$ ($3 \le N \le 20$) hay bales from the shed. Every bale is exactly one unit tall, and each bale has its own distinct width and distinct breadth.

A second cow stacks some of the bales into a tower. A bale may rest on another bale only if the bale below has a strictly larger width and a strictly larger breadth than the bale on top. Bales may not be rotated, so width and breadth can never be swapped.

Determine the height of the tallest tower the cows can legally build. Because every bale is one unit tall, the height of a tower equals the number of bales it contains.

Input

  • Line 1: A single integer $N$.
  • Lines 2 to $N+1$: Each line contains two space-separated integers, the width and the breadth of one bale.

Output

  • Line 1: The height of the tallest tower that can legally be built from the bales.

Hint

In the example, five of the six bales can be stacked into a tower of height $5$, and another valid stacking of the same height also exists.