#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;
}


Measured memory_bytes: 19944