#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500007;
int main() {
  int i, l, r, ans, n;
  pair<int, int> a[MAXN];
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> l >> r;
    a[i] = make_pair(l, r);
  }
  sort(a, a + n);
  ans = 1;
  r = a[0].second;
  for (i = 1; i < n; i++) {
    if (a[i].first > r) {
      ans++;
      r = a[i].second;
      continue;
    }
    if (a[i].second < r) r = a[i].second;
  }
  cout << ans << endl;
  return 0;
}
