#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FORD(i,a,b) for (int i=a;i>=b;i--)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const int MO=1e9+7;
pa a[200010];
int n,l[200010],ans,b[200010],s[200010],mn,mx,r[200010],L,R,tmp[200010],f[200010],ts;
int main(){
	scanf("%d",&n);
	FOR(i,1,n){
		scanf("%d%d",&a[i].fi,&a[i].se);
		tmp[++ts]=a[i].se;
	}
	sort(tmp+1,tmp+ts+1);
	ts=unique(tmp+1,tmp+ts+1)-tmp-1;
	sort(a+1,a+n+1);
	FOR(i,1,n){
		b[i]=lower_bound(tmp+1,tmp+ts+1,a[i].se)-tmp;
	}
	mx=0;
	FOR(i,1,n){
		mx=max(mx,b[i]);
		r[i]=mx;
	}
	mn=n+1;
	FORD(i,n,1){
		mn=min(mn,b[i]);
		l[i]=mn;
	}
	f[0]=s[0]=1;
	L=0;
	FOR(R,1,n){
		while (L<R && r[L]<l[R]-1) ++L;
		f[R]=(s[R-1]-s[L-1]+MO)%MO;
		s[R]=(s[R-1]+f[R])%MO;
	}
	FOR(R,1,n)
		if (r[R]==ts) (ans+=f[R])%=MO;
	cout<<ans<<endl;
	return 0;
}
