acwing803:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 200010;
typedef pair<int,int> PII;
int n;
vector<PII> add,res;
int main(){
cin >> n;
for(int i = 0 ; i < n ; i ++){
int l ,r;
cin >> l >> r;
add.push_back({l,r});
}
sort(add.begin(),add.end());//排序,会先按左端点排序再按右端点排序
int st = -2e9,ed = -2e9;//起点区间设为最左边
for(auto item : add) {
if(item.first > ed) {//上一区间和当前区间无交集
st = item.first;
ed = item.second;
res.push_back({st,ed});
}
else if(item.first == ed){//上一区间和当前区间刚好相连
ed = item.second;
if(res.size()>=1) res.pop_back();//若上一区间不为空,弹出
res.push_back({st,ed});
}
else if(item.second > ed){//上一区间和当前区间交错
ed = item.second;
res.pop_back();
res.push_back({st,ed});
}
}
cout << res.size() <<endl;
return 0;
}