#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=3e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
#define x first
#define y second
int x[N],mx[N],f[N];
pair<int,int>p[N];
inline bool cmp(const pair<int,int> &a,const pair<int,int> &b) { return a.y==b.y?a.x<b.x:a.y<b.y; }
int main()
{
	int n=gi(),i,j,l,r,t,mid,len,ans=0;
	for (i=1;i<=n;i++) p[i].x=gi(),p[i].y=x[i]=gi();
	sort(x+1,x+1+n);len=unique(x+1,x+1+n)-x-1;
	for (i=1;i<=n;p[i++].y=l) for (l=1,r=len;l!=r;p[i].y<=x[mid=(l+r)>>1]?r=mid:l=mid+1);
	sort(p+1,p+1+n);
	for (i=1;i<=n;i++) mx[i]=max(mx[i-1],p[i].y);
	for (i=n,t=1<<30;i;i--) p[i]=make_pair(t=min(t,p[i].y),mx[i]);
	sort(p+1,p+1+n,cmp);
	const int mod=1e9+7;
	f[0]=1;
	for (i=1,j=0;i<=n;i++) {
		/*
		for (t=p[i-1].y+1;t<=p[i].y;t++)
			(f[t]+=f[t-1])%=mod;
		t=f[p[i].y];
		if (p[i].x!=1) (t-=f[p[i].x-2])%=mod;
		(f[p[i].y]+=t)%=mod;*/
		while (p[j].y<p[i].x-1) j++;
		f[i]=(f[i-1]-(j?f[j-1]:0)+mod)%mod;
		if (p[i].y==len) (ans+=f[i])%=mod;
		(f[i]+=f[i-1])%=mod;
	}
	//printf("%d\n",(f[len]-f[len-1]+mod)%mod);
	printf("%d\n",(ans+mod)%mod);
	return 0;
}
