#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e5+5,mo=1e9+7;
int n,i,mn[N],mx,lt[N],f[N],g[N];
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
struct arr{int x,k;}a[N];
bool operator < (arr A,arr B){return A.x<B.x;}
bool cmp(arr A,arr B){return A.k<B.k;}
int main(){
	for (n=read(),i=1;i<=n;i++)
		a[i]=(arr){read(),read()};
	sort(a+1,a+n+1);
	for (i=1;i<=n;i++) a[i].x=i;
	sort(a+1,a+n+1,cmp);
	for (mn[n]=a[n].x,i=n-1;i;i--)
		mn[i]=min(mn[i+1],a[i].x);
	for (i=1;i<=n;i++){
		mx=max(mx,a[i].x);
		lt[mx]=max(lt[mx],mn[i]);
	}
	f[0]=g[0]=1;mx=0;
	for (i=1;i<=n;i++){
		f[i]=(g[i-1]-(mx?g[mx-1]:0))%mo;
		g[i]=(g[i-1]+f[i])%mo;
		mx=max(mx,lt[i]);
	}
	printf("%d",((g[n]-(mx?g[mx-1]:0))%mo+mo)%mo);
}