// Original C++ solution (slower):
#include<cstdio>

#include<iostream>

#include<algorithm>

using namespace std;

const int N = 2e5+5;

const int mod = 1e9+7;

const int inf = 0x3f3f3f3f;



int n, f[N], c[N], mx[N], mn[N], ans = 0;



struct line{ int x, v, L, R; }a[N];



int lowbit(int x){ return x & (-x); }



void update(int x, int val){

	for(; x <= n; x += lowbit(x)) (c[x] += val) %= mod;

}



int query(int x){

	int res = 0;

	for(; x; x -= lowbit(x)) (res += c[x]) %= mod;

	return res;

}



bool cmp1(line a, line b){ return a.v < b.v; }

bool cmp2(line a, line b){ return a.R != b.R ? a.R < b.R : a.L < b.L; }



int main(){

//	freopen("river.in", "r", stdin);

//	freopen("river.out", "w", stdout);

	ios::sync_with_stdio(false);

	cin >> n;

	for(int i = 1; i <= n; i++) cin >> a[i].x >> a[i].v;

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

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

		int l = 1, r = i-1; mx[i] = max(mx[i-1], a[i].x);

		while(l <= r){

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

			if(mx[mid] > a[i].x) a[i].L = mid, r = mid-1;

			else l = mid+1;

		}

	}

	mn[n+1] = inf;

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

		int l = i+1, r = n; mn[i] = min(mn[i+1], a[i].x);

		while(l <= r){

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

			if(mn[mid] < a[i].x) a[i].R = mid, l = mid+1;

			else r = mid-1;

		}

	}

	for(int i = 1; i <= n; i++) a[i].L ? 0 : a[i].L = i, a[i].R ? 0 : a[i].R = i;

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

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

		if(a[i].L == 1) f[i] = (f[i]+1)%mod;

		f[i] += (query(a[i].R)-query(max(a[i].L-2, 0))+mod)%mod;

		if(a[i].R == n) (ans += f[i]) %= mod;

		update(a[i].R, f[i]);

	}

	cout << ans << endl;

	return 0;

}

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

#include <algorithm>

#define ri register int

namespace io {

    const int SIZE = (1 << 21) + 1;

    char ibuf[SIZE], *iS, *iT, c; int f;

    // getchar

    #define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)

    // input a signed integer

    template <class I>

    inline void gi (I &x) {

        for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;

        for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;

    }

}

using io :: gi;

const int N=500005,inf=1<<30,mod=1000000007;

int mn[N],mx[N],f[N],sum[N];

struct node{

	int k,b,l,r;

}a[N];

inline bool cmp(node p,node q){

	return p.b>q.b;

}

inline bool cmp2(node p,node q){

	return p.l<q.l||(p.l==q.l&&p.r<q.r);

}

inline int min(ri x,ri y){

	return x<y ? x:y;

}

inline int max(ri x,ri y){

	return x>y ? x:y;

}

int main(){

    ri n,i,pos,l,r,mid,j,ans=0;

    gi(n);

    for(i=1;i<=n;++i) gi(a[i].k),gi(a[i].b);

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

    mn[0]=inf;

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

    	mn[i]=min(mn[i-1],a[i].k);

    	l=0;r=i-1;pos=i;

    	while(l<=r){

    		mid=l+r>>1;

    		if(mn[mid]<a[i].k) pos=mid,r=mid-1;

    		else l=mid+1;

		} 

		a[i].l=pos;

	}

	mx[n+1]=-inf; 

	for(i=n;i;--i){

		mx[i]=max(mx[i+1],a[i].k);

		l=i+1;r=n;pos=i;

		while(l<=r){

			mid=l+r>>1;

			if(mx[mid]>a[i].k) pos=mid,l=mid+1;

			else r=mid-1;

		} 

		a[i].r=pos;

	}

	std::sort(a+1,a+1+n,cmp2);

	j=1;

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

		while(a[j].r+1<a[i].l) ++j;

		f[i]=(sum[i-1]-sum[j-1]+mod)%mod;

		if(a[i].l==1) f[i]=(f[i]+1)%mod;

		//可以只选i这个区间就覆盖1~i这么多区间的范围 

		sum[i]=(sum[i-1]+f[i])%mod;

		if(a[i].r==n) ans=(ans+f[i])%mod;//第i个区间可以作为最后一个选的区间 

	}

	printf("%d\n",ans);

    return 0;

}

// Fastest known solution for this problem: