#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=5e5,mod=1e9+7;;
int f[N],s[N],n,tmpx[N],l[N],r[N],w[N];
struct Node{int x,v;}a[N];
int cmp1(const Node &a,const Node &b){return a.v<b.v;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].v),tmpx[i]=a[i].x;
	sort(tmpx+1,tmpx+n+1);
	for(int i=1;i<=n;i++)a[i].x=lower_bound(tmpx+1,tmpx+n+1,a[i].x)-tmpx;
	sort(a+1,a+n+1,cmp1);
	for(int i=1;i<=n;i++)w[a[i].x]=i;
	for(int i=1;i<=n;i++)r[i]=max(r[i-1],w[i]);
	l[n+1]=n+1;for(int i=n;i>=1;i--)l[i]=min(l[i+1],w[i]);
	s[0]=1;
	for(int i=1;i<=n;i++)
		f[i]=(s[i-1]-(l[i]==1?0:s[lower_bound(r+1,r+i,l[i]-1)-r-1]))%mod,s[i]=(s[i-1]+f[i])%mod;
	cout<<((s[n]-s[lower_bound(r+1,r+n+1,n)-r-1])%mod+mod)%mod;
}