#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
const int N=200001;
const int mod=1e9+7;
int n,f[N],F[N+1];
void inc(int&a,int b){a+=b;if(a>=mod)a-=mod;}
void upd(int x,int s){for(x++;x>=1;x-=x&-x)inc(F[x],s);}
int ask(int x){int s=0;for(x++;x<=n+1;x+=x&-x)inc(s,F[x]);return s;}
struct xint{int x,y;}s[N],p[N];
bool cmpx(xint a,xint b){return a.x<b.x;}
bool cmpy(xint a,xint b){return a.y<b.y;}
int main(){
	scanf("%d",&n);
	ref(i,1,n)scanf("%d%d",&s[i].x,&s[i].y);
	sort(s+1,s+n+1,cmpy);
	ref(i,1,n)s[i].y=i;
	sort(s+1,s+n+1,cmpx);
	p[1].y=s[1].y;
	ref(i,2,n)p[i].y=max(p[i-1].y,s[i].y);
	p[n].x=s[n].y;
	def(i,n-1,1)p[i].x=min(p[i+1].x,s[i].y);
	f[0]=1;upd(0,1);
	int ans=0;
	ref(i,1,n){
		f[i]=ask(p[i].x-1);
		upd(p[i].y,f[i]);
		if(p[i].y==n)inc(ans,f[i]);
	}
	printf("%d\n",ans);
}