#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;
struct Range{
int l,r;
}range[N];
bool cmp(struct Range a,struct Range b){
return a.r<b.r;
}
int main(){
ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=0;i<n;i++){
int l,r;
cin>>l>>r;
range[i]={l,r};
}
sort(range,range+n,cmp);
int res=0,ed=-2e9;
for(int i=0;i<n;i++){
if(ed<range[i].l){
res++;
ed=range[i].r;
}
}
cout<<res;
}