#include <stdio.h>
#include <utility>
#include <queue>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
struct cmp{
  bool operator()(const pi &a,const pi &b){
      return a.S>b.S;
  }  
};
int main(){
    int n,ans=0,last=0;
    pi temp;
    priority_queue<pi,vector<pi>,cmp>pq;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d",&temp.F,&temp.S);
        pq.push(temp);
    }
    while(!pq.empty()){
        if(pq.top().F<=last)pq.pop();
        else{
            ans++;
            last=pq.top().S;
            pq.pop();
        }
    }
    printf("%d\n",ans);
}
