#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10,INF=0x3f3f3f3f;
int n;
struct Range{
int l,r;
bool operator <(const Range &W)const{
return r<W.r;
}
}range[N];
int main(){
cin>>n;
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
range[i]={a,b};
}
sort(range,range+n);
int res=0,ed=-INF;
for(int i=0;i<n;i++){
if(range[i].l>ed){
res++;
ed=range[i].r;
}
}
cout<<res<<endl;
}