#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define ji -
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define fe(x) for(int i=be[x];i;i=e[i].ne)
using namespace std;
const int p=1e9+7;
int n,na[210000],rk[210000],m;
long long f[210000];
struct nod{
	int x,v;
	bool operator <(const nod &a)const{
		return x<a.x;
	}
};
nod a[210000];
bool cmp(int c,int d){
	return a[c].v<a[d].v;
}
struct seg{
	int l,r;
	bool operator <(const seg &a)const{
		return r<a.r||(r==a.r&&l<a.l);
	}
};
seg e[210000];
inline long long sum(int x){
	long long ans=0;
	while (x){
		ans+=f[x];
		x-=x&(-x);
	}
	return ans;//!!!!!!!!!!
}
inline void add(int x,int v){
	while (x<=m){
		f[x]+=v;
		x+=x&(-x);
	}
}
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d%d",&a[i].x,&a[i].v);
	sort(a+1,a+n+1);
	fo(i,1,n) na[i]=i;
	sort(na+1,na+n+1,cmp);
	fo(i,1,n) rk[na[i]]=i;
	int t=1;
	fo(i,1,n){
		if (a[i].v>a[t].v) t=i;
		e[i].r=rk[t];
	}
	t=n;
	fd(i,n,1){
		if (a[i].v<a[t].v) t=i;
		e[i].l=rk[t];
	}
	sort(e+1,e+n+1);
	m=n+1;
	add(1,1);
	/*printf("----after0---\n");
	fo(i,1,m) printf("%I64d ",sum(i)-sum(i-1));
	putchar('\n');*/
	fo(i,1,n){
		add(e[i].r+1,(sum(e[i].r+1)-sum(e[i].l-1))%p);
		/*printf("----after%d---\n",i);
		fo(i,1,m) printf("%I64d ",sum(i)-sum(i-1));
		putchar('\n');*/
	}
	printf("%d\n",(sum(n+1)-sum(n)+p)%p);
	return 0;
}