QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 128 MB

#23517. Power Lines

Estadísticas

As power lines were added one by one between two utility poles $A$ and $B$, some of them began to cross. Because of the risk of a short circuit, we want to remove some of these lines so that no lines cross.

For example, when the lines are connected as in Figure 1, removing the line from position $1$ on $A$ to position $8$ on $B$, the line from position $3$ on $A$ to position $9$ on $B$, and the line from position $4$ on $A$ to position $1$ on $B$ leaves no crossings among the remaining lines.

problem_23517_f0777293e1b8dd052549110b2894c931.jpg

The positions where lines connect to a pole are numbered consecutively from top to bottom. Given the number of lines and the position numbers where they connect to the two poles, write a program to find the minimum number of lines that must be removed so that none of the remaining lines cross.

Input

The first line contains the number of power lines between the two poles. This is a positive integer at most $100$.

Starting from the second line, each line gives, in order, the position number where a power line connects to pole $A$ and the position number where it connects to pole $B$.

Each position number is a positive integer at most $500$, and two or more lines cannot connect at the same position.

Output

On the first line, output the minimum number of lines that must be removed so that no remaining lines cross.

Examples

Input 1

8
1 8
3 9
2 2
4 1
6 4
10 10
9 7
7 6

Output 1

3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.