// Original C++ solution (slower):
#include <bits/stdc++.h>



#define f first

#define s second

#define pb push_back

#define mp make_pair



using namespace std;



typedef long long ll;

typedef pair<int, int> pii;

typedef pair<long long, long long> pll;



const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;

const ll INF = 1e18;



int n, a[N], b[N], p[N], l[N], r[N], t1[N << 2], t2[N << 2], t[N << 2], s[N << 2];

vector< int > va, vb;

vector< pii > v;

void upd1(int v, int tl, int tr, int pos,int val){

	if(tl == tr){

		t1[v] = val;

		return;

	}

	int tm = (tl + tr) >> 1;          

	if(pos <= tm)

		upd1(v << 1, tl, tm, pos, val);

	else

		upd1(v << 1 | 1, tm + 1, tr, pos, val);

	t1[v] = min(t1[v << 1], t1[v << 1 | 1]);

}

int get1(int v, int tl, int tr, int l, int r){

	if(r < tl || tr < l)

		return inf;

	if(l <= tl && tr <= r)

		return t1[v];

	int tm = (tl + tr) >> 1;

	return min(get1(v << 1, tl, tm, l, r), get1(v << 1 | 1, tm + 1, tr, l, r));

}

void upd2(int v, int tl, int tr, int pos,int val){

	if(tl == tr){

		t2[v] = val;

		return;

	}

	int tm = (tl + tr) >> 1;          

	if(pos <= tm)

		upd2(v << 1, tl, tm, pos, val);

	else

		upd2(v << 1 | 1, tm + 1, tr, pos, val);

	t2[v] = max(t2[v << 1], t2[v << 1 | 1]);

}

int get2(int v, int tl, int tr, int l, int r){

	if(r < tl || tr < l)

		return -inf;

	if(l <= tl && tr <= r)

		return t2[v];

	int tm = (tl + tr) >> 1;

	return max(get2(v << 1, tl, tm, l, r), get2(v << 1 | 1, tm + 1, tr, l, r));

}

void push(int v){                              

	t[v << 1] = 1ll * t[v << 1] * s[v] % mod;

	s[v << 1] = 1ll * s[v << 1] * s[v] % mod;

	t[v << 1 | 1] = 1ll * t[v << 1 | 1] * s[v] % mod;

	s[v << 1 | 1] = 1ll * s[v << 1 | 1] * s[v] % mod;

	s[v] = 1;

}

void updp(int v, int tl, int tr, int pos, int val){

	if(tl == tr){

		t[v] = (t[v] + val) % mod;

		return;

	}

	push(v);

	int tm = (tl + tr) >> 1;

	if(pos <= tm)

		updp(v << 1, tl, tm, pos, val);

	else

		updp(v << 1 | 1, tm + 1, tr, pos, val);

	t[v] = (t[v << 1] + t[v << 1 | 1]) % mod;	

}

void upds(int v, int tl, int tr, int l, int r){

	if(r < tl || tr < l)

		return;

	if(l <= tl && tr <= r){

		t[v] = (t[v] + t[v]) % mod;

		s[v] = (s[v] + s[v]) % mod;

		return;

	}

	push(v);

	int tm = (tl + tr) >> 1;

	upds(v << 1, tl, tm, l, r);

	upds(v << 1 | 1, tm + 1, tr, l, r);

	t[v] = (t[v << 1] + t[v << 1 | 1]) % mod;	

}

int get(int v, int tl, int tr, int l, int r){

	if(r < tl || tr < l)

		return 0;

	if(l <= tl && tr <= r)

		return t[v];

	push(v);

	int tm = (tl + tr) >> 1;

	return (get(v << 1, tl, tm, l, r) + get(v << 1 | 1, tm + 1, tr, l, r)) % mod;

}

main()

{                         

	scanf("%d", &n);

	for(int i = 1; i <= n; i++){

		scanf("%d%d", &a[i], &b[i]);

		va.pb(a[i]);

		vb.pb(b[i]);

	}                           

	sort(va.begin(), va.end());

	sort(vb.begin(), vb.end());

	for(int i = 1; i <= n; i++)

		p[lower_bound(vb.begin(), vb.end(), b[i]) - vb.begin() + 1] = lower_bound(va.begin(), va.end(), a[i]) - va.begin() + 1;

	

	for(int i = 0; i < (N << 2); i++)

		t1[i] = inf, t2[i] = -inf, s[i] = 1;



	for(int i = 1; i <= n; i++){

		upd1(1, 1, n, p[i], i);      

		l[i] = get1(1, 1, n, p[i], n);

	}

	for(int i = n; i >= 1; i--){

		upd2(1, 1, n, p[i], i);      

		r[i] = get2(1, 1, n, 1, p[i]);

	}

	for(int i = 1; i <= n; i++)

		v.pb({r[i], i});

	sort(v.begin(), v.end());

	updp(1, 1, n + 1, 1, 1);

	for(auto it : v){

		int i = it.s;

		upds(1, 1, n + 1, 1, l[i] - 1);

        upds(1, 1, n + 1, r[i] + 1, n + 1);

		updp(1, 1, n + 1, r[i] + 1, get(1, 1, n + 1, l[i], r[i]));

	}

	printf("%d", get(1, 1, n + 1, n + 1, n + 1));

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstring>

#include<cstdio>

#include<vector>

#include<algorithm>

#include<iostream>

#define mod 1000000007

#define maxn 200100

#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;

ll tree[maxn*4];

int minn[maxn],maxx[maxn];

void pu(int rt) {

	tree[rt]=(tree[rt*2]+tree[rt*2+1])%mod;

}

ll query(int rt,int l,int r,int al,int ar) {

	if(al<=l&&ar>=r) {

		return tree[rt];

	}

	int mid=(l+r)>>1;

	ll sum=0;

	if(al<=mid) {

		sum+=query(rt*2,l,mid,al,ar);

		sum%=mod;

	}

	if(ar>mid) {

		sum+=query(rt*2+1,mid+1,r,al,ar);

		sum%=mod;

	}

	pu(rt);

	return sum;

}

void add(int rt,int l,int r,int pos,ll val) {

	if(l==r) {

		tree[rt]+=val;

		tree[rt]%=mod;

		return;

	}

	int mid=(l+r)>>1;

	if(pos<=mid) add(rt*2,l,mid,pos,val);

	else add(rt*2+1,mid+1,r,pos,val);

	pu(rt);

	return;

}

struct node {

	ll x,v;

	int pos;

} a[maxn];

struct line {

	int l,r;

} seg[maxn];

int lll[maxn],rrr[maxn];

bool cmpv(node a,node b) {

	return a.v<b.v;

}

bool cmpx(node a,node b) {

	return a.x<b.x;

}

bool cmpseg(line a,line b) {

	if(a.r==b.r) return a.l<b.l;

	return a.r<b.r;

}

int main() {

	ll N;

	cin >> N;

	for(int i=1; i<=N; i++) {

		scanf("%lld%lld",&a[i].x,&a[i].v);

	}

	memset(lll,0,sizeof(lll));

	memset(rrr,0,sizeof(rrr));

	sort(a+1,a+1+N,cmpv);

	for(int i=1; i<=N; i++) {

		a[i].pos=i;

	}

	sort(a+1,a+1+N,cmpx);

	for(int i=1;i<=N;i++) {

		minn[i]=INF;

		maxx[i]=-1;

	}

	minn[N]=a[N].pos;

	for(int i=N-1;i>0;i--) {

		minn[i]=min(minn[i+1],a[i].pos);

	}

	for(int i=1;i<=N;i++) {

		lll[a[i].pos]=minn[i];

	}

	maxx[1]=a[1].pos;

	for(int i=2;i<=N;i++) {

		maxx[i]=max(maxx[i-1],a[i].pos);

	}

	for(int i=1;i<=N;i++) {

		rrr[a[i].pos]=maxx[i];

	}

	for(int i=1;i<=N;i++) {

		seg[i].l=lll[i],seg[i].r=rrr[i];

	}

	sort(seg+1,seg+1+N,cmpseg);

	memset(tree,0,sizeof(tree));

	ll ans=0;

	for(int i=1;i<=N;i++) {

		ll tmp=0;

		if (seg[i].l==1) tmp++;

		tmp+=query(1,1,N,seg[i].l-1,seg[i].r);

		tmp%=mod;

		add(1,1,N,seg[i].r,tmp);

		if(seg[i].r>=N) {

			ans+=tmp;

			ans%=mod;

		}

	}

	cout << ans << endl;

}

// Fastest known solution for this problem: