#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
struct Range{
int l,r;
bool operator <(const Range &W)const{
return l<W.l;
}
}range[N];
int n;
int main(){
cin>>n;
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
range[i]={a,b};
}
sort(range,range+n);
priority_queue<int,vector<int>, greater<int> > heap;
for(int i=0;i<n;i++){
if(heap.size()==0||heap.top()>=range[i].l) heap.push(range[i].r); //新加一个区间
else{
heap.pop();
heap.push(range[i].r);
}
}
cout<<heap.size()<<endl;
}