#include <bits/stdc++.h>
using namespace std;
struct Seg {
  int l, r;
};
Seg s[500010];
bool cmp(Seg i, Seg j) { return i.r < j.r; }
int sum, g;
int main() {
  int n;
  cin >> n;
  for (int t = 1; t <= n; t++) scanf("%d%d", &s[t].l, &s[t].r);
  sort(s + 1, s + 1 + n, cmp);
  g = 0;
  for (int t = 1; t <= n; t++) {
    if (s[t].l > g) {
      sum++;
      g = s[t].r;
    }
  }
  cout << sum << endl;
  return 0;
}
