Bus Routes#1424

Bus Routes

3 seconds
64 megabytes
Hard

In a country with a rectangular shape, the network of intercity highways is simple. Each highway is a straight line running strictly from north to south or from west to east, connecting opposite borders of the country. Cities are located at some of the highway intersections, and no two cities are on the same highway.

The country was once wealthy and spent its budget rather carelessly. For example, there was a direct bus route between every pair of cities, allowing passengers to travel from one city to another by the shortest possible route without stops.

However, when the budget for the next year was being planned, it became clear that the income from intercity transport was much less than the cost of maintaining such a network. Therefore, it was decided to reduce the number of routes as much as possible. To avoid public dissatisfaction with transfers, it was required that the shortest travel distance between any two cities must remain unchanged.

Input

The first line contains a single natural number — the number of cities, 2 \leq N \leq 10000.

The next lines each contain two non-negative integers x_i, y_i — the numbers of the highways at whose intersection each city is located (x_i is the number of the north-south highway, and y_i is the number of the west-east highway).

Highways in each direction are numbered consecutively from up to . North-south highways are numbered from west to east, and west-east highways are numbered from north to south.

Output

The first line should contain a single integer — the minimum number of bus routes that must be retained.

Examples

Example 1

Loading
Loading