#include<iostream>
#include<vector>
#include<iomanip>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
bool cmp(time f,time p)
{
return f.b<p.b;
}
struct time
{
int a;
int b;
};
int main()
{
struct time sj[1000001];
int n,t;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>sj[i].a>>sj[i].b;
}
sort(sj,sj+n,cmp);
int mark=0;
int count=1;
for(int i=0;i<n;i++)
{
if(sj[i].a>mark)
{
count++;
mark=sj[i].b;
}
}
cout<<count;
return 0;
}