Tianjin University Online Judge
Contests Virtual Contests Problems Submit Runs Status Rank List Forum

2769.   The Bale Tower
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 1483   Accepted Runs: 529    Multiple test files



Always bored with cud-chewing, the cows have invented a new game. One cow retrieves a set of N (3 ≤ N ≤ 20) hay bales from the shed each of which is one unit high. Each bale also has some unique width and unique breadth.

A second cow tries to choose a set of bales to make the tallest stack of bales in which each bale can be placed only on a bale whose own width and breadth are smaller than the width and breadth of the bale below. Bales can not be rotated to interchange the width and breadth.

Help the cows determine the highest achievable tower that can be legally built form a set of bales.

Input

* Line 1: A single integer, N

* Lines 2..N + 1: Each line describes a bale with two space-separated integers,respectively the width and breadth

Output

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

Sample Input

6
6 9
10 12
9 11
8 10
7 8
5 3

Sample Output

5

Input Details

Six bales of various widths and breadths

Output Details

These bales can be stacked for a total height of 5:
10 12
9 11
8 10
6 9
5 3
[another stacking exists, too]



Source: USACO 2007 January Competition
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.3.0
Maintance:Fxz. Developer: SuperHacker, G.D.Retop, Fxz