#include <bits/stdc++.h>
int n;
struct seg {
  int l, r;
} s[500005];
bool cmp(const seg &a, const seg &b) { return a.r < b.r; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d%d", &s[i].l, &s[i].r);
  std::sort(s, s + n, cmp);
  int r = s[0].r, ans = 1;
  for (int i = 1; i < n; ++i) {
    if (s[i].l > r) {
      r = s[i].r;
      ++ans;
    }
  }
  printf("%d", ans);
  return 0;
}
