#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
int n;
vector<PII> segs;
void merge(vector<PII> &segs)
{
vector<PII> res;
sort(segs.begin(),segs.end());//按左端点排序
int st=-2e9,ed=-2e9;//起点 终点
for (int i = 0; i < n; i ++ )//遍历数组
if(ed < segs[i].x)//如果两个区间没有交集
{
if(st!=-2e9) res.push_back({st,ed});//并且不是初始化的起点 那就放入数组中
st=segs[i].x,ed=segs[i].y;//更新st ed
}
else ed = max(ed,segs[i].y);//有交集 就取最大的交集
if(st!=-2e9) res.push_back({st,ed});//把最后一个区间也放入答案数组中
segs=res;
}
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
int l , r;
cin >> l >> r;
segs.push_back({l,r});
}
merge(segs);
cout<<segs.size()<<endl;
return 0;
}