#include<cstdio>
#include<algorithm>
const int N=2e5+3,M=1e9+7;
struct node{int x,v;}a[N];
struct segment{int l,r;}c[N];
bool Cmpa(const node&a,const node&b){return a.x<b.x;}
bool Cmpc(const segment&a,const segment&b){return a.r<b.r;}
int n,b[N],f[N];
int main(){
	int s,t,m,mx;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].v);
	std::sort(a+1,a+1+n,Cmpa);
	b[0]=0;
	for(int i=1;i<=n;i++){
	  for(s=1,t=i;s<t;)m=s+t>>1,b[m]>a[i].v?t=m:s=m+1;
	  c[i].l=s;
	  b[i]=std::max(b[i-1],a[i].v);
	}
	b[n+1]=M;
	for(int i=n;i;i--){
	  for(s=i,t=n;s<t;)m=s+t+1>>1,b[m]<a[i].v?s=m:t=m-1;
	  c[i].r=t;
	  b[i]=std::min(b[i+1],a[i].v);
	}
	std::sort(c+1,c+1+n,Cmpc);
	mx=0,f[0]=1;
	for(int i=1,j=1;i<=n;i++){
	  f[i]=(2ll*f[i-1]-(mx?f[mx-1]:0)+M)%M;
	  for(;j<=n&&c[j].r<=i;j++)mx=std::max(mx,c[j].l);
	}
	printf("%d\n",(f[n]-f[mx-1]+M)%M);
	return 0;
}