Олимпиадный тренинг

Задача 39377. Particle Mu


Having delved into the study of physics in quarantine, the cows discovered "mu-particles"
They are currently experimenting with N "mu-particles" (1 ≤N ≤ 105). Particle i has a "spin" described by two integers xi and yi in the range −109…10 9 inclusive. Sometimes two "mu-particles" interact. This can only happen to particles with spins (xi,yi) and (xj,yj) that have xi≤xj and yi≤yj. Under these conditions, exactly one of these particles disappears (and nothing happens to the other). At most one interaction can happen at any given time.

The cows want to know the minimum number of "mu-particles" that can remain after some arbitrary sequence of interactions.

Input
The first line contains one integer N, the initial number of "mu-particles". Each of the following N lines contains two space-separated integers defining the spin of this particle. All spins are different.
Imprint
One integer, the minimum number of "mu-particles" that can remain after some arbitrary sequence of interactions.
Examples
# Input Output Note
1 4
10
0 1
-1 0
0 -1
1 One of the possible interaction sequences:

Particles 1 and 4 interact, particle 1 disappears.
Particles 2 and 4 interact, particle 4 disappears.
Particles 2 and 3 interact, particle 3 disappears.
Only particle 2 remains.
2 3
0 0
1 1
-1 3
2 Particle 3 cannot interact with any of the other particles, so it must remain. One of particles 1 and 2 should also remain.