Under construction

Still being built. Things may change

Swords

Interview

Time limit1sMemory limit1024 MB

Summary
Count the swords that no other sword matches or beats in both attack and defence.
Level

Easy3 of 10

Topics
Sorting, Array
Solved
No attempts yet

Problem

Yan Hao has nn swords numbered from 1 to nn. Sword ii has attack aia_i and defence bib_i.

Yan Hao considers sword ii useless if there is a different sword jj (j≠ij \ne i) such that ai≤aja_i \le a_j and bi≤bjb_i \le b_j. In other words, sword ii is useless when another sword matches or beats it in both attack and defence. A sword that is not useless is useful.

Two swords are equivalent if they have the same attack and the same defence. No two swords are equivalent.

Find the number of useful swords.

Input

The first line contains one integer nn.

Each of the next nn lines contains two space-separated integers. The ii-th of these lines contains aia_i and bib_i, the attack and defence of sword ii.

Output

Print one integer, the number of useful swords.

Constraints

  • 1≤n≤100 0001 \le n \le 100\,000
  • 1≤ai,bi≤1091 \le a_i, b_i \le 10^9
  • For all 1≤i<j≤n1 \le i < j \le n, ai≠aja_i \ne a_j or bi≠bjb_i \ne b_j.

Examples2

  1. Example 1

    Input
    3
    2 3
    1 3
    5 3
    
    Expected output
    1
    
  2. Example 2

    Input
    4
    5 6
    2 5
    6 9
    1 3
    
    Expected output
    1