#include<algorithm>
#include<cstdio>
#define N 200005
#define p 1000000007
using namespace std;
int a[N],b[N],c[N],d[N],f[N],l,m,n,r,s[N],t;
inline bool cmp(int u,int v){return a[u]<a[v];}
inline bool CMP(int u,int v){return c[u]==c[v]?b[u]<b[v]:c[u]<c[v];}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",a+i,b+i),c[i]=d[i]=i;
	sort(c+1,c+n+1,cmp);
	for(int i=1;i<=n;i++)a[i]=b[c[i]];
	for(int i=1,l,o,r;i<=n;b[i++]=s[l])
	{
		for(l=0,r=t;l<r;)o=l+r>>1,a[s[o]]>a[i]?r=o:l=o+1;
		if(l==t)s[t++]=i;
	}t=0;
	for(int i=n,l,o,r;i;c[i--]=s[l])
	{
		for(l=0,r=t;l<r;)o=l+r>>1,a[s[o]]<a[i]?r=o:l=o+1;
		if(l==t)s[t++]=i;
	}
	sort(d+1,d+n+1,CMP),*f=1;
	for(int i=1,j=0;i<=n;i++)
	{
		while(j<=n&&c[d[j+1]]<i)j++;
		if(b[d[j]])f[i]=f[i-1]>=f[b[d[j]]-1]?f[i-1]-f[b[d[j]]-1]:p+f[i-1]-f[b[d[j]]-1];
		else f[i]=f[i-1];
		f[i]=f[i]+f[i-1]>=p?f[i]+f[i-1]-p:f[i]+f[i-1];
	}
	printf("%d\n",f[n]>=f[b[d[n]]-1]?f[n]-f[b[d[n]]-1]:p+f[n]-f[b[d[n]]-1]);
	return 0;
}