import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
List<int[]> list = new ArrayList<>();
while (n-- > 0) {
int a = sc.nextInt(), b = sc.nextInt();
list.add(new int[] {a, b});
}
list.sort((a, b) -> a[1] - b[1]);
int right = Integer.MIN_VALUE, ans = 0;
for (int[] num : list) {
if (right != Integer.MIN_VALUE && num[0] <= right) ans++;
else right = num[1];
}
System.out.println(ans);
sc.close();
}
}