#include <bits/stdc++.h>
using namespace std;
const int MaxN = 5e5;
int n;
struct pp {
  int x;
  int y;
} a[MaxN + 5];
bool cmp(pp a, pp b) { return a.y < b.y; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", &a[i].x, &a[i].y);
  sort(a, a + n, cmp);
  int cnt = 0;
  int k = a[0].y;
  for (int i = 1; i < n; i++) {
    if (a[i].x <= k)
      cnt++;
    else
      k = a[i].y;
  }
  printf("%d\n", n - cnt);
  return 0;
}
