#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
typedef pair<int, int> PII;
PII p[N];
bool cmp(PII a, PII b){
return a.second < b.second;
}
int main(){
int n, cnt = 0;
cin>>n;
for(int i = 0; i < n; i++){
cin>>p[i].first>>p[i].second;
}
sort(p, p + n, cmp);
for(int i = 0, ed = -2e9; i < n; i++){
int l = p[i].first, r = p[i].second;
if(l > ed){
cnt++;
ed = r;
}
}
cout<<cnt<<endl;
return 0;
}