#include <bits/stdc++.h>
using namespace std;
long long ans;
int n, a, b;
vector<pair<int, int> > v;
int main() {
  ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &a, &b);
    v.push_back(make_pair(b, a));
  }
  sort(v.begin(), v.end());
  for (int i = 0, j = 0; i < v.size(); ++i) {
    if (v[i].second > j) {
      j = v[i].first;
      ++ans;
    }
  }
  printf("%I64d", ans);
  return 0;
}
