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

#define sqr(x) ((x)*(x))

#define ll long long

#define ull unsigned long long

#define ui unsigned int

#define ld long double

#define vi vector<int>

#define pii pair<int,int>

#define pb push_back

#define mp make_pair

#define debuge cerr<<"isok"<<endl

#define debug(x) cerr<<#x<<"="<<x<<endl

#define SS second

#define FF first

#define ls (k<<1)

#define rs (k<<1|1)

#define inf 0x3f3f3f3f

#define clr(a,x) memset(a,x,sizeof(a))

#define cpy(a,x) memcpy(a,x,sizeof(a))

#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);

using namespace std;

 

const int N=200005,M=100005,mod=1e9+7;

template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}

template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}

inline void ch(int &x,int y){x=(x+y)%mod;}

inline void read(int &x){

	x=0;char ch=getchar();

	while(ch>'9'||ch<'0') ch=getchar();

	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();

}

 

struct node{int x,y;}a[N],q[N];

int n,m,yy[N],mx=0,mn=inf;

int p[N<<2],flag[N<<2];

 

inline bool cmp(const node &a,const node &b){return a.x<b.x;}

inline void add(int k,int b){

	p[k]=(ll)p[k]*b%mod,flag[k]=(ll)flag[k]*b%mod;

}

inline void push(int k){

	if(flag[k]==1) return;

	add(ls,flag[k]);add(rs,flag[k]);

	flag[k]=1;

}

inline void ch(int l,int r,int x,int k,int b){

	if(l==r){ch(p[k],b);return;}

	int mid=l+r>>1;

	push(k);

	if(x<=mid) ch(l,mid,x,ls,b); else ch(mid+1,r,x,rs,b);

	p[k]=(p[ls]+p[rs])%mod;

}

inline void mul(int l,int r,int x,int y,int k){

	if(x<=l&&r<=y){add(k,2);return;}

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

	if(x<=mid) mul(l,mid,x,y,ls);

	if(y>mid) mul(mid+1,r,x,y,rs);

	p[k]=(p[ls]+p[rs])%mod;

}

inline int get(int l,int r,int x,int y,int k){

	if(x<=l&&r<=y) return p[k];

	push(k);int ans=0,mid=l+r>>1;

	if(x<=mid) ch(ans,get(l,mid,x,y,ls));

	if(y>mid) ch(ans,get(mid+1,r,x,y,rs));

	return ans;

}

 

int main(){

	scanf("%d",&n);

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

		scanf("%d%d",&a[i].x,&a[i].y),yy[i]=a[i].y;

	sort(yy+1,yy+n+1);

	m=unique(yy+1,yy+n+1)-yy-1;

	for(int i=1;i<=n;i++) a[i].y=lower_bound(yy+1,yy+m+1,a[i].y)-yy;

//	for(int i=1;i<=n;i++) printf("%d %d\n",a[i].x,a[i].y);

	sort(a+1,a+n+1,cmp);

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

		int l=i,r=i;

		while(r<=n&&a[r].x==a[l].x) r++;

		for(int j=l;j<r;j++)

			q[j].y=max(mx,a[j].y);

		for(int j=l;j<r;j++)

			gmax(mx,a[j].y);

		i=r-1;

	}

	reverse(a+1,a+n+1);

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

		int l=i,r=i;

		while(r<=n&&a[r].x==a[l].x) r++;

		for(int j=l;j<r;j++)

			q[n-j+1].x=min(mn,a[j].y);

		for(int j=l;j<r;j++)

			gmin(mn,a[j].y);

		i=r-1;

	}

	sort(q+1,q+n+1,cmp);

	for(int i=1;i<=800000;i++) flag[i]=1;

//	for(int i=1;i<=n;i++) printf("%d %d\n",q[i].x,q[i].y);

//	return 0;

	ch(0,m,0,1,1);

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

		int k=get(0,m,q[i].x-1,q[i].y,1);

		ch(0,m,q[i].y,1,k);

		if(q[i].y<m) mul(0,m,q[i].y+1,m,1);

	}

	printf("%d\n",get(0,m,m,m,1));

	return 0;

}

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

#include <algorithm>

#include <utility>



const int maxn = 2e5 + 10, mod = 1e9 + 7;



int n, hsh[maxn], dp[maxn];

std::pair<int, int> pnt[maxn], rng[maxn];



inline int lowbit(int i) {

	return i & (-i);

}



inline void M(int i, int x) {

	for (; i <= n; i += lowbit(i)) {

		dp[i] = (dp[i] + x) % mod;

	}

	return;

}



inline int Q(int i) {

	if(i < 0) {

		return 0;

	}

	int x = 0;

	for (; i; i ^= lowbit(i)) {

		x = (x + dp[i]) % mod;

	}

	return x;

}



int main() {

	scanf("%d", &n);

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

		int x, y;

		scanf("%d%d", &x, &y);

		pnt[i] = std::make_pair(x, y);

		hsh[i] = y;

	}

	std::sort(hsh, hsh + n);

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

		pnt[i].second = std::lower_bound(hsh, hsh + n, pnt[i].second) - hsh + 1;

	}

	std::sort(pnt, pnt + n);

	int mx = 0, mn = n + 1;

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

		mx = std::max(mx, pnt[i].second);

		rng[i].second = mx;

	}

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

		mn = std::min(mn, pnt[i].second);

		rng[i].first = mn;

	}

	std::sort(rng, rng + n);

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

		int l = rng[i].first, r = rng[i].second;

		M(r, (Q(r) - Q(l - 2) + (l == 1)) % mod);

	}

	printf("%d\n", (Q(n) - Q(n - 1) + mod) % mod);

	return 0;

}


// Fastest known solution for this problem: