#include <iostream>
#include <algorithm>
using namespace std;
const int N=100005;
struct Node{
int l,r;
bool operator<(const Node &b)const{
return r<b.r;
}
}node[N];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++){
int l,r;
cin>>l>>r;
node[i]={l,r};
}
sort(node+1,node+n+1);
int res=0,ed=-2e9;
for(int i=1;i<=n;i++){
if(node[i].l>ed){
ed=node[i].r;
res++;
}
}
cout<<res;
//cout << "Hello world!" << endl;
return 0;
}