#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
void read(int& x)
{
x = 0;char c = getchar();
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
}
#define MAXN 1000010
#define forx(i,s,t) for(int i = (s);i <= (t);i++)
int low[MAXN],high[MAXN];
int bestans,nowans,last;
void swap(int& x,int& y)
{
int t = x;
x = y;
y = t;
}
int main(void)
{
#define MYAK
#ifdef MYAK
freopen("sequence.in","r",stdin);
freopen("sequence.out","w",stdout);
#endif
read(n);
forx(i,1,n)read(low[i]),read(high[i]);
bestans = nowans = 1;
last = low[1];
forx(i,2,n)
{
if(high[i]<last)
{
bestans = max(bestans,nowans);
nowans = 1;
last = low[i];
}
else
{
++nowans;
if(low[i]<=last)continue;
else last = low[i];
}
}
bestans = max(bestans,nowans);
forx(i,1,n/2)swap(low[i],low[n-i+1]),swap(high[i],high[n-i+1]);
nowans = 1;
last = high[1];
forx(i,2,n)
{
if(low[i]>last)
{
bestans = max(bestans,nowans);
nowans = 1;
last = high[i];
}
else
{
++nowans;
if(high[i]>=last)continue;
else last = high[i];
}
}
bestans = max(bestans,nowans);
printf("%d\n",bestans);
return 0;
}
|