#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int n;
struct Seg
{
int s,e;
bool operator< (const Seg &W) const
{
return s < W.s;
}
}segs[N];
int main()
{
cin>>n;
for(int i=0;i<n;i++) cin>>segs[i].s>>segs[i].e;
sort(segs,segs+n);
int res = 0;
priority_queue<int, vector<int>, greater<int>> heap;
for(int i=0;i<n;i++)
{
auto t = segs[i];
if(heap.empty()||t.s<=heap.top()) heap.push(t.e);
else
{
heap.pop();
heap.push(t.e);
}
}
printf("%d\n",heap.size());
return 0;
}