#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
    using namespace std;
    #define pii pair<int,int>
    #define fir first
    #define sec second
    #define MP make_pair
    #define rep(i,x,y) for (int i=(x);i<=(y);i++)
    #define drep(i,x,y) for (int i=(x);i>=(y);i--)
    #define go(x) for (int i=head[x];i;i=edge[i].nxt)
    #define templ template<typename T>
    #define mod 1000000007ll
    #define sz 233333
    typedef long long ll;
    typedef double db;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
    templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
    templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
    templ inline void read(T& t)
    {
        t=0;char f=0,ch=getchar();double d=0.1;
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
        if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
        t=(f?-t:t);
    }
    template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
    char __sr[1<<21],__z[20];int __C=-1,__zz=0;
    inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
    inline void print(register int x)
    {
        if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
        while(__z[++__zz]=x%10+48,x/=10);
        while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
    }
    void file()
    {
        #ifdef NTFOrz
        freopen("a.in","r",stdin);
        #endif
    }
    inline void chktime()
    {
        #ifndef ONLINE_JUDGE
        cout<<(clock()-t)/1000.0<<'\n';
        #endif
    }
    #ifdef mod
    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
    ll inv(ll x){return ksm(x,mod-2);}
    #else
    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
    #endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n;
struct hh{int l,r;const bool operator < (const hh &x) const {return r<x.r;}}a[sz],A[sz];
int pre[sz];

pii W[sz];int w[sz];

ll sum[sz<<2],tag[sz<<2];
#define ls k<<1
#define rs k<<1|1
#define lson ls,l,mid
#define rson rs,mid+1,r
void Mul(int k,ll w){(sum[k]*=w)%=mod,(tag[k]*=w)%=mod;}
void pushdown(int k){Mul(ls,tag[k]),Mul(rs,tag[k]);tag[k]=1;}
void pushup(int k){sum[k]=(sum[ls]+sum[rs])%mod;}
ll query(int k,int l,int r,int x,int y)
{
	if (x>y) return 0;
	if (x<=l&&r<=y) return sum[k];
	int mid=(l+r)>>1;
	pushdown(k);
	ll ret=0;
	if (x<=mid) (ret+=query(lson,x,y))%=mod;
	if (y>mid) (ret+=query(rson,x,y))%=mod;
	return ret;
}
void mul(int k,int l,int r,int x,int y)
{
	if (x>y) return;
	if (x<=l&&r<=y) return Mul(k,2);
	int mid=(l+r)>>1;
	pushdown(k);
	if (x<=mid) mul(lson,x,y);
	if (y>mid) mul(rson,x,y);
	pushup(k);
}
void add(int k,int l,int r,int x,ll w)
{
	if (l==r) return (void)(sum[k]+=w);
	pushdown(k);
	int mid=(l+r)>>1;
	if (x<=mid) add(lson,x,w);
	else add(rson,x,w);
	pushup(k);
}
void build(int k,int l,int r)
{
	tag[k]=1;
	if (l==r) return;
	int mid=(l+r)>>1;
	build(lson),build(rson);
}

int Pre[sz],Suf[sz];

int main()
{
    file();
	read(n);
	rep(i,1,n) read(W[i].fir,W[i].sec);
	sort(W+1,W+n+1);rep(i,1,n) w[i]=W[i].sec;
	rep(i,1,n) Pre[i]=max(Pre[i-1],w[i]);
	Suf[n+1]=1e9;drep(i,n,1) Suf[i]=min(Suf[i+1],w[i]);
	rep(i,1,n) a[i].l=lower_bound(Pre+1,Pre+n+1,w[i])-Pre;
	rep(i,1,n) a[i].r=upper_bound(Suf+1,Suf+n+1,w[i])-Suf-1;
	sort(a+1,a+n+1);
	rep(i,1,n) pre[i]=max(pre[i-1],a[i].l);
	rep(i,1,n) 
	{
		int l,r;
		l=lower_bound(a+1,a+n+1,(hh){0,i})-a-1;
		r=upper_bound(pre+1,pre+n+1,i)-pre;
		A[i]=(hh){l+1,r-1};
	}
	sort(A+1,A+n+1);
	build(1,1,n+1);
	add(1,1,n+1,1,1);
	rep(i,0,n-1)
	{
		mul(1,1,n+1,1,A[i+1].l-1);
		add(1,1,n+1,A[i+1].r+1,query(1,1,n+1,A[i+1].l,A[i].r+1));
	}
	cout<<query(1,1,n+1,n+1,n+1);
	return 0;
}

Measured memory_bytes: 20480