#include <bits/stdc++.h>
using namespace std;
const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}

inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=2e5+50, mod=1e9+7;
inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
inline int dec(int x,int y) {return (x-y<0) ? (x-y+mod) : (x-y);}

int n,a[N],b[N],l[N],r[N],lim[N];
inline void lsh(int *c) {
	vector <int> vec;
	for(int i=1;i<=n;i++) vec.push_back(c[i]);
	sort(vec.begin(),vec.end());
	for(int i=1;i<=n;i++) c[i]=lower_bound(vec.begin(),vec.end(),c[i])-vec.begin()+1;
}
int mn[N<<2],mx[N<<2];
inline void upt(int k) {mx[k]=max(mx[k<<1],mx[k<<1|1]), mn[k]=min(mn[k<<1],mn[k<<1|1]);}
inline void build(int k,int l,int r,int t) {
	if(l==r) {mx[k]=mn[k]=t; return;}
	int mid=(l+r)>>1;
	build(k<<1,l,mid,t);
	build(k<<1|1,mid+1,r,t);
	upt(k);
}
inline void inc(int k,int l,int r,int p,int v) {
	if(l==r) {mx[k]=mn[k]=v; return;}
	int mid=(l+r)>>1;
	(p<=mid) ? inc(k<<1,l,mid,p,v) : inc(k<<1|1,mid+1,r,p,v);
	upt(k);
} 
inline int ask(int k,int l,int r,int L,int R,int type) {
	if(L<=l && r<=R) {return (type ? mx[k] : mn[k]);}
	int mid=(l+r)>>1;
	if(R<=mid) return ask(k<<1,l,mid,L,R,type);
	else if(L>mid) return ask(k<<1|1,mid+1,r,L,R,type);
	else {
		int v1=ask(k<<1,l,mid,L,R,type), v2=ask(k<<1|1,mid+1,r,L,R,type);
		return (type ? max(v1,v2) : min(v1,v2));
	}
}

namespace ST {
	int s[N<<2],tag[N<<2];
	inline void cov(int k) {tag[k]=1; s[k]=0;}
	inline void pushdown(int k) {if(tag[k]) cov(k<<1), cov(k<<1|1), tag[k]=0;}
	inline void upt(int k) {s[k]=add(s[k<<1],s[k<<1|1]);}
	inline void inc(int k,int l,int r,int p,int v) {
		if(l==r) {s[k]=add(s[k],v); return;}
		pushdown(k); int mid=(l+r)>>1;
		(p<=mid) ? inc(k<<1,l,mid,p,v) : inc(k<<1|1,mid+1,r,p,v);
		upt(k);
	}
	inline void cov(int k,int l,int r,int L,int R) {
		if(L<=l && r<=R) {cov(k); return;}
		pushdown(k); int mid=(l+r)>>1;
		if(R<=mid) cov(k<<1,l,mid,L,R);
		else if(L>mid) cov(k<<1|1,mid+1,r,L,R);
		else cov(k<<1,l,mid,L,R), cov(k<<1|1,mid+1,r,L,R);
		upt(k);
	}
	inline int ask(int k,int l,int r,int L,int R) {
		if(L<=l && r<=R) return s[k];
		pushdown(k); int mid=(l+r)>>1;
		if(R<=mid) return ask(k<<1,l,mid,L,R);
		else if(L>mid) return ask(k<<1|1,mid+1,r,L,R);
		else return add(ask(k<<1,l,mid,L,R),ask(k<<1|1,mid+1,r,L,R));
	}
	inline void inc(int p,int v) {inc(1,0,n,p,v);}
	inline void cov(int p,int v) {cov(1,0,n,p,v);}
	inline int ask(int l,int r) {return ask(1,0,n,l,r);}
};
int main() {
	n=rd();
	for(int i=1;i<=n;i++) a[i]=rd(), b[i]=rd();
	lsh(a); lsh(b);
	for(int i=1;i<=n;i++) l[a[i]]=b[i];
	for(int i=1;i<=n;i++) b[i]=l[i];
	build(1,1,n,n+1);
	for(int i=1;i<=n;i++) {
		inc(1,1,n,b[i],i);
		l[i]=ask(1,1,n,b[i],n,0);
	}
	build(1,1,n,0);
	for(int i=n;i>=1;i--) {
		inc(1,1,n,b[i],i);
		r[i]=ask(1,1,n,1,b[i],1);
	}
	for(int i=1;i<=n;i++) lim[r[i]]=max(lim[r[i]],l[i]);
	ST::inc(0,1);
	for(int i=1;i<=n;i++) {
		int s=ST::ask(0,n);
		if(lim[i]) ST::cov(0,lim[i]-1);
		ST::inc(i,s);
	}
	cout<<ST::ask(0,n)<<'\n';
}

Measured memory_bytes: 16976