#include <cstdio>
#include <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i)
using namespace std;

typedef long long LL;
const int p=1000000007;
int n,l[200100],r[200100],pow2[200100],f[200100],sum[200100];
struct data1
{
    int x,v,p;
    bool operator<(const data1 &t) const
    {
        return v<t.v;
    }
} a[200100];
struct data2
{
    int l,r;
    bool operator<(const data2 &t) const
    {
        return r<t.r || r==t.r && l>t.l;
    }
} b[200100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()) && ch!='-');
    bool flag=ch=='-';
    if (flag)
        ch=getchar();
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return flag?-x:x;
}

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

int main()
{
    n=getint();
    repu(i,1,n)
        a[i].x=getint(),a[i].v=getint();
    sort(a+1,a+1+n),pow2[0]=1;
    repu(i,1,n)
        a[i].p=i,pow2[i]=pow2[i-1]*2%p;
    sort(a+1,a+1+n,cmp),l[n+1]=n;
    repd(i,n,1)
        l[i]=min(l[i+1],a[i].p);
    repu(i,1,n)
        b[i]=(data2){l[i],r[i]=max(r[i-1],a[i].p)};
    sort(b+1,b+1+n),f[0]=sum[0]=1;
    for (int i=1,j=1,k; i<=n; ++i,j=k)
    {
        for (k=j; b[k].r==i; ++k)
            f[i]=(f[i]+LL(b[k].l>1?sum[i-1]+p-sum[b[k].l-2]:sum[i-1])*pow2[k-j])%p;
        sum[i]=(sum[i-1]+f[i])%p;
    }
    printf("%d\n",f[n]);
    return 0;
}