#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
//#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

const double PI = acos(-1);
const double EPS = 1e-9;

const int MX = 1<<18;
const int MM = 1000000007;

struct Tree{
	int t[MX*2];
	int (*f)(int, int);
	void update(int x, int v){
		x += MX; t[x] = v;
		while(x > 1){
			x /= 2;
			t[x] = f(t[x*2], t[x*2+1]);
		}
	}
	int read(int s, int e){
		s += MX, e += MX;
		assert(s <= e);
		int r = t[s];
		while(s <= e){
			if( s&1 ) r = f(r, t[s++]);
			if(~e&1 ) r = f(r, t[e--]);
			s /= 2, e /= 2;
		}
		return r;
	}
}mn, mx;

struct Segtree{
	struct node{
		int mul, sum;
	}t[MX*2];

	void pushdown(int n){
		if( n >= MX ) return;
		if( t[n].mul != 1 ){
			t[n*2].mul = t[n*2].mul * t[n].mul % MM;
			t[n*2].sum = t[n*2].sum * t[n].mul % MM;
			t[n*2+1].mul = t[n*2+1].mul * t[n].mul % MM;
			t[n*2+1].sum = t[n*2+1].sum * t[n].mul % MM;
			t[n].mul = 1;
		}
	}

	void update(int x, int v, int n = 1, int s = 0, int e = MX-1){
		pushdown(n);
		if( s == e ) t[n].sum = (t[n].sum + v) % MM;
		else{
			int m = (s+e) / 2;
			if( x <= m ) update(x, v, n*2, s, m);
			else update(x, v, n*2+1, m+1, e);
			t[n].sum = (t[n*2].sum + t[n*2+1].sum) % MM;
		}
	}
	void mul(int l, int r, int v, int n = 1, int s = 0, int e = MX-1){
		pushdown(n);
		if( r < s || e < l );
		else if( l <= s && e <= r ){
			t[n].mul = t[n].mul * v % MM;
			t[n].sum = t[n].sum * v % MM;
		}
		else{
			int m = (s+e) / 2;
			mul(l, r, v, n*2, s, m);
			mul(l, r, v, n*2+1, m+1, e);
			t[n].sum = (t[n*2].sum + t[n*2+1].sum) % MM;
		}
	}
	int sum(int l, int r, int n = 1, int s = 0, int e = MX-1){
		pushdown(n);
		if( r < s || e < l ) return 0;
		else if( l <= s && e <= r ) return t[n].sum;
		else{
			int m = (s+e) / 2;
			return (sum(l, r, n*2, s, m) + sum(l, r, n*2+1, m+1, e)) % MM;
		}
	}
} tree;

int N;
pii D[MX], A[MX];
int mnf(int x, int y){ return x < y? x : y; }
int mxf(int x, int y){ return x > y? x : y; }

int main()
{
	vector<int> Y;
	mn.f = mnf, mx.f = mxf;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		scanf("%d%d", &D[i].first, &D[i].second);
		Y.push_back(D[i].second);
	}
	sort(Y.begin(), Y.end());
	sort(D+1, D+N+1);
	for(int i = 1; i < MX*2; i++) tree.t[i].mul = 1;
	for(int i = 1; i <= N; i++) D[i].second = upper_bound(Y.begin(), Y.end(), D[i].second) - Y.begin();
	for(int i = 1; i <= N; i++) mn.update(i, D[i].second), mx.update(i, D[i].second);

	for(int i = 1; i <= N; i++){
		int u = mn.read(i, N), v = mx.read(1, i);
		A[i] = pii(u, v);
	}
	sort(A+1, A+N+1);
	tree.update(0, 1);

	for(int i = 1; i <= N; i++){
		int u = A[i].first, v = A[i].second;
		int tot = tree.sum(u-1, v-1);
		tree.mul(v, N, 2);
		tree.update(v, tot);
	}
	printf("%d\n", tree.sum(N, N));
}


Measured memory_bytes: 12916