#include<bits/stdc++.h>
using namespace std;
struct times{
long long time1;
long long time2;
}p[10000];
long long cmp(struct times a,struct times b){
if(a.time2 < b.time2){
return 1;
}else{
return 0;
}
}
long long k,cnt;
long long s = 0;
int main(){
cin >> k;
for(int i = 0;i < k;i++){
cin >> p[i].time1 >> p[i].time2;
}
sort(p,p+k,cmp);
for(int i = 0;i < k;i++){
if(s <= p[i+1].time1){
s = p[i+1].time2;
cnt++;
}
}
cout << cnt;
return 0;
}