#include<bits/stdc++.h>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
	char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const int mod=1e9+7;const int maxn=2e5+5;
struct Seg{int x,y;}c[maxn];
struct Goast{int x,v;}a[maxn];
int n,mx[maxn],mn[maxn],b[maxn],pre[maxn],dp[maxn];
inline int dqm(int x) {return x<0?x+mod:x;}
inline int qm(int x) {return x>=mod?x-mod:x;}
inline int cop(const Goast &A,const Goast &B) {return A.x<B.x;}
inline int ctp(const Seg &A,const Seg &B) {return A.y==B.y?A.x<B.x:A.y<B.y;}
inline int find(int v) {
	int l=0,r=n,nw=-1;
	while(l<=r) {
		int mid=l+r>>1;
		if(c[mid].y<v) nw=mid,l=mid+1;else r=mid-1;
	}
	return nw;
} 
int main() {
	//freopen("data.in","r",stdin);
	//freopen("my.out","w",stdout);
	n=read();for(re int i=1;i<=n;i++) a[i].x=read(),b[i]=a[i].v=read();
	std::sort(b+1,b+n+1);
	for(re int i=1;i<=n;i++) a[i].v=std::lower_bound(b+1,b+n+1,a[i].v)-b;
	std::sort(a+1,a+n+1,cop);c[n].x=a[n].v;
	for(re int i=n-1;i;i--) c[i].x=min(c[i+1].x,a[i].v);
	for(re int i=1;i<=n;i++) c[i].y=max(c[i-1].y,a[i].v);
	std::sort(c+1,c+n+1,ctp);dp[0]=pre[0]=1;int ans=0;
	for(re int i=1;i<=n;i++) {
		int t=find(c[i].x-1);
		dp[i]=dqm(pre[i-1]-(t==-1?0:pre[t]));
		pre[i]=qm(pre[i-1]+dp[i]);
	}
	//for(re int i=1;i<=n;i++) printf("%d %d %d\n",c[i].x,c[i].y,dp[i]);
	for(re int i=1;i<=n;i++)if(c[i].y==n)ans=qm(ans+dp[i]);
	printf("%d\n",ans);
	return 0;
}
