//srt: 10:40
//end: 11:20
#include<cstdio>
#include<algorithm>
#include<functional>
inline void read(int&r)
{
	register char c;r=0;
	do c=getchar();while(c!='-'&&(c<'0'||c>'9'));
	register bool f=c=='-'&&(c=getchar());
	do r=r*10+c-'0',c=getchar();while(c>='0'&&c<='9');
	f&&(r=-r);
}

const int N=200002,mod=1e9+7;
#define x first
#define v second
#define l second
#define r first
std::pair<int,int>a[N];
int dp[N],b[N],p[N];
int main()
{
	int i,j,n,c,m;read(n);
	for(i=0;i<n;i++)read(a[i].x),read(a[i].v),b[i]=a[i].v;
	std::sort(a,a+n);
	std::sort(b,b+n,std::greater<int>());
	m=std::unique(b,b+n)-b;

	for(i=n-1,c=0;i>=0;i--)
	{
		a[i].v=std::upper_bound(b,b+m,a[i].v,std::greater<int>())-b;
		a[i].v>c&&(c=a[i].v);
		a[i].r=c;
	}

	for(i=0,c=m+1;i<n;i++)
	{
		a[i].v<c&&(c=a[i].v);
		a[i].l=c;
	}

	std::sort(a,a+n);
	a[n].r=m+1;

	dp[0]=p[1]=1;
	for(i=1,j=0;i<=m;i++)
	{
		while(a[j].r==i)
		{
			(dp[i]<<=1)>=mod&&(dp[i]-=mod);
			dp[i]+=p[i]-p[a[j++].l-1];
			dp[i]>=mod&&(dp[i]-=mod);
			dp[i]<0&&(dp[i]+=mod);
		}
		(p[i+1]=dp[i]+p[i])>=mod&&(p[i+1]-=mod);
	}

	printf("%d\n",dp[m]);
}