#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> PII;
vector<PII>a,b;
void merset(vector<PII>&a)
{
    
    int st=-2e9,ed=-2e9;
    for(auto c : a)//遍历a
    {
      if(ed>=c.first)
      {
        ed=max(ed,c.second);//两个区间有交集,合并
      }
      else {
      if(ed!=-2e9)b.push_back({st,ed});
      st=c.first;
      ed=c.second;
    }
    }
    if(ed!=-2e9)b.push_back({st,ed});//将最后一个区间放入b中
}
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int l,r;
        cin>>l>>r;
        a.push_back({l,r});
    }
    sort(a.begin(),a.end());
    merset(a);
    cout<<b.size();
}