区间合并
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
typedef pair<int ,int> PII;
vector<PII> A,B;
void merge()
{
sort(A.begin(),A.end());
int st = -2e9,ed = -2e9;
for(auto c : A)
{
if(ed<c.first)
{
if(st != -2e9) B.push_back({st,ed});
st = c.first, ed = c.second;
}
else ed = max(ed,c.second);
}
if(st != -2e9) B.push_back({st,ed});
}
int main()
{
int n;
cin>>n;
while(n--)
{
int l,r;
cin>>l>>r;
A.push_back({l,r});
}
merge();
cout<<B.size();
return 0;
}