#include <bits/stdc++.h>

using namespace std;

bool comp(pair<int, int> &a, pair<int, int> &b) {
   if (a.first != b.first) {
      return a.first < b.first;
   }
   return a.second > b.second;
}


int main(){
   int n; cin >> n;

   vector<pair<int, int>> intervals(n);
   for (int i = 0; i < n; i++) {
      cin >> intervals[i].first;
      cin >> intervals[i].second;
   }

   sort(intervals.begin(), intervals.end(), comp);

   int lastCovered = intervals[0].second;
   int count = 1;
   for (int i = 1; i < n; i++) {
      if (lastCovered < intervals[i].second) {
         lastCovered = intervals[i].second;
         count++;
      }
   }

   cout << count << endl;

   return 0;
}