#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
int n;
struct line {
  int l, r;
  bool operator<(const line &x) const { return r < x.r; }
} a[MAXN];
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) scanf("%d %d", &a[i].l, &a[i].r);
  int last = 0, ans = 0;
  sort(a + 1, a + 1 + n);
  for (register int i = 1; i <= n; ++i) {
    if (a[i].l > a[last].r) {
      last = i;
      ans++;
    }
  }
  printf("%d", ans);
  return 0;
}
