#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> a[511000];
bool cmp(pair<long long, long long>& a, pair<long long, long long>& b) {
  if (a.first != b.first)
    return (a.first < b.first);
  else
    return (a.second < b.second);
}
long long b[511000];
int main() {
  int n;
  long long ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  sort(a, a + n);
  long long last = 0;
  ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i].first > last) {
      ans++;
      last = a[i].second;
    } else {
      last = min(last, a[i].second);
    }
  }
  cout << ans;
}
