#include<bits/stdc++.h>
using namespace std;
int com,ans;
bool vis[100005],flag;
struct game{
int begin;
int end;
}games[100005];
bool cmp(game x,game y){
if(x.end==y.end) return x.begin>y.begin;
return x.end<y.end;
}
int main(){
cin>>com;
for(int i=1;i<=com;i++) cin>>games[i].begin>>games[i].end;
sort(games+1,games+com+1,cmp);
for(int i=1;i<=com;i++) {
for(int j=games[i].begin;j<games[i].end;j++)
if(vis[j]==1) {
flag=1;
break;
}
if(flag) {
flag=0;
continue;
}
ans++;
for(int j=games[i].begin;j<games[i].end;j++) vis[j]=1;
}
cout<<ans;
return 0;
}