#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long n, l, r, end = 0, ans = 0;
  cin >> n;
  pair<long, long> p[n];
  for (long i = 0; i < n; i++) cin >> p[i].second >> p[i].first;
  sort(p, p + n);
  for (long i = 0; i < n; i++) {
    if (p[i].second > end) {
      end = p[i].first;
      ans++;
    }
  }
  cout << ans;
}
