#include <bits/stdc++.h>
using namespace std;
void FastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
pair<int, int> ppp[500010];
int main() {
  FastIO();
  int N, ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> ppp[i].second >> ppp[i].first;
  sort(ppp, ppp + N);
  int curr = -1;
  for (int i = 0; i < N; i++) {
    if (ppp[i].second >= curr) {
      ans++;
      curr = (ppp[i].first) + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
