#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[500005];
int cmp(pair<int, int> fir, pair<int, int> sec) {
  if (fir.second < sec.second) return 1;
  if (fir.second > sec.second) return 0;
  return fir.first < sec.first;
}
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d%d", &a[i].first, &a[i].second);
  sort(a, a + n, cmp);
  int ans = 0;
  int x, y;
  x = -2;
  y = -1;
  for (i = 0; i < n; i++) {
    if (a[i].first > y) {
      ans++;
      y = a[i].second;
    }
  }
  printf("%d\n", ans);
}
