#include <bits/stdc++.h>
using namespace std;
bool comp(pair<unsigned long long, unsigned long long> p1,
          pair<unsigned long long, unsigned long long> p2) {
  return p1.second < p2.second;
}
int main() {
  unsigned long long i, n, first, second, count = 1;
  vector<pair<unsigned long long, unsigned long long> > v;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> first >> second;
    v.push_back(make_pair(first, second));
  }
  sort(v.begin(), v.end(), comp);
  second = v[0].second;
  for (i = 1; i < v.size(); i++) {
    if (second < v[i].first) {
      second = v[i].second;
      count++;
    }
  }
  cout << count;
}
