#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
#define N 510000
#define md 1000000007
using namespace std;
int read()
{
	int x=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
ll dp[N],sum;
int ex[N],cnt,q[N],size,l[N],r[N],n,m,tmp,i,head,tail;
struct node {int v,x;}a[N];
bool cmp(node x,node y){return x.x<y.x;}
void init()
{
	sort(ex+1,ex+1+cnt);size=unique(ex+1,ex+1+cnt)-ex-1;
	for (ll i=1;i<=n;i++) l[i]=upper_bound(ex+1,ex+1+size,l[i])-ex-1,r[i]=upper_bound(ex+1,ex+1+size,r[i])-ex-1;
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)a[i].x=read(),a[i].v=read();
	sort(a+1,a+1+n,cmp);
	for (i=1;i<=n;i++) tmp=max(tmp,a[i].v),r[i]=tmp;
	tmp=2000000000;for (i=n;i>=1;i--) tmp=min(tmp,a[i].v),l[i]=tmp;
	for (i=1;i<=n;i++) ex[++cnt]=a[i].v;
	init();
	dp[0]=1;n++;l[n]=r[n]=n;
	q[++tail]=0;sum=1;
	for (i=1;i<=n;i++) 
	{
		while (head!=tail&&r[q[head+1]]<l[i]-1) sum=(sum-dp[q[head+1]]+md)%md,head++;
		dp[i]=sum;sum=(sum+dp[i])%md;
		q[++tail]=i;
	}
	printf("%lld\n",dp[n]%md);
}