//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 200005
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
const int mod=1000000007;
vector<int> e[N];
int n,l[N],r[N],f[N],s[N];
struct node
{
	int x,v,id;
	bool operator < (const node &i)const
	{
		return v<i.v;
	}
}p[N];
bool cmp(node a,node b)
{
	return a.x<b.x;
}
int main()
{
	re(n);
	for(int i=1;i<=n;++i)
		re(p[i].x),re(p[i].v);
	sort(p+1,p+n+1);
	for(int i=1;i<=n;++i)p[i].id=i;
	sort(p+1,p+n+1,cmp);
	r[1]=p[1].id;
	for(int i=2;i<=n;++i)
		r[i]=max(r[i-1],p[i].id);
	l[n]=p[n].id;
	for(int i=n-1;i;--i)
		l[i]=min(l[i+1],p[i].id);
	for(int i=1;i<=n;++i)
		e[r[i]].push_back(l[i]);
	f[0]=s[0]=1;
	for(int i=1;i<=n;++i)
	{
		for(int j:e[i])
			f[i]=(2ll*f[i]+s[i-1]-(j==1?0:s[j-2]))%mod;
		f[i]=(f[i]+mod)%mod;
		s[i]=(s[i-1]+f[i])%mod;
	}
	printf("%d\n",f[n]);
}
