#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N=500005,mod=1000000007;

int n,t[N],Q[N],L[N],R[N],f[N];

vector<int> V[N];

struct node
{
	int b,k;
}p[N];

bool cmp(node x1,node x2)
{
	if(x1.k!=x2.k) return x1.k<x2.k;
	return x1.b<x2.b;
}

int lowbit(int x)
{
	return x&(-x);
}

void update(int x,int k)
{
	++x;
	for(;x<=n+1;x+=lowbit(x)) t[x]=(t[x]+k)%mod;
	return ;
}

int query(int x)
{
	if(x<=0) return 0;
	int res=0;
	for(;x>=1;x-=lowbit(x)) res=(res+t[x])%mod;
	return res;
}

int query(int l,int r)
{
	++l;
	++r;
	return (query(r)-query(l-1)+mod)%mod;
}

signed main()
{
	//freopen("river.in","r",stdin);
	//freopen("river.out","w",stdout);
	ios::sync_with_stdio(false);
	int cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>p[i].b>>p[i].k;
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		if(cnt==0||p[i].b>p[Q[cnt]].b) Q[++cnt]=i;
		int l=1,r=cnt,ans=i;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(p[Q[mid]].b>p[i].b)
			{
				ans=Q[mid];
				r=mid-1;
			}
			else l=mid+1;
		}
		L[i]=ans;
	}
	cnt=0;
	for(int i=n;i>=1;i--)
	{
		if(cnt==0||p[i].b<p[Q[cnt]].b) Q[++cnt]=i;
		int l=1,r=cnt,ans=i;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(p[Q[mid]].b<p[i].b)
			{
				ans=Q[mid];
				r=mid-1;
			}
			else l=mid+1;
		}
		R[i]=ans;
	}
	for(int i=1;i<=n;i++) V[R[i]].push_back(L[i]);
	f[0]=1;
	update(0,1);
	for(int i=1;i<=n;i++)
	{
		sort(V[i].begin(),V[i].end());
		for(int j=0;j<V[i].size();j++) 
		{
			int x=query(V[i][j]-1,i);
			f[i]=(f[i]+x)%mod;
			update(i,x);
		}
	}
	cout<<f[n]<<endl;
	return 0;
}
