#include <bits/stdc++.h>
using namespace std;

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

    int start[a], temp;
    multimap<int,int>finish;
    map<int,int>::iterator it;

    for(int i=0;i<a;i++) {
        cin >> start[i] >> temp;
        finish.insert(make_pair(temp,i));
    }

    int currentTime=0,activityCount=0, activityList[a];
    int i=0;
    for(it=finish.begin();it!=finish.end();it++)
    {

        int currentFinishTime = it->first;
        int currentActivity = it->second;
        if(start[currentActivity]>currentTime) {
            currentTime = currentFinishTime;
            activityCount++;
            activityList[i++] = currentActivity;
        }
    }


    cout << activityCount << endl;

    return 0;
}
