#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define mod 1000000007
using namespace std;
int n,ans;
int seq[200010],mn[800010],mx[800010],sum[800010];
struct Node
{
    int st,v;
} data[200010];
bool operator<(const Node &a,const Node &b)
{
    return a.v<b.v;
}
struct Seg
{
    int l,r;
} line[200010];
bool operator<(const Seg &a,const Seg &b)
{
    if(a.r==b.r)
        return a.l<b.l;
    else return a.r<b.r;
}
void modify(int x,int l,int r,int pos,int v)
{
    if(l==r)
    {
        mn[x]=mx[x]=v;
        sum[x]+=v;
        if(sum[x]>=mod)
            sum[x]-=mod;
        return;
    }
    int mid=(l+r)>>1;
    if(pos<=mid)
        modify(x<<1,l,mid,pos,v);
    else modify(x<<1|1,mid+1,r,pos,v);
    mn[x]=min(mn[x<<1],mn[x<<1|1]);
    mx[x]=max(mx[x<<1],mx[x<<1|1]);
    sum[x]=sum[x<<1]+sum[x<<1|1];
    if(sum[x]>=mod)
        sum[x]-=mod;
}
int getmin(int x,int l,int r,int a,int b)
{
    if(a<=l&&r<=b)
        return mn[x];
    int mid=(l+r)>>1;
    if(b<=mid)
        return getmin(x<<1,l,mid,a,b);
    else if(a>mid)
        return getmin(x<<1|1,mid+1,r,a,b);
    else return min(getmin(x<<1,l,mid,a,b),getmin(x<<1|1,mid+1,r,a,b));
}
int getmax(int x,int l,int r,int a,int b)
{
    if(a<=l&&r<=b)
        return mx[x];
    int mid=(l+r)>>1;
    if(b<=mid)
        return getmax(x<<1,l,mid,a,b);
    else if(a>mid)
        return getmax(x<<1|1,mid+1,r,a,b);
    else return max(getmax(x<<1,l,mid,a,b),getmax(x<<1|1,mid+1,r,a,b));
}
int getsum(int x,int l,int r,int a,int b)
{
    if(a<=l&&r<=b)
        return sum[x];
    int mid=(l+r)>>1;
    if(b<=mid)
        return getsum(x<<1,l,mid,a,b);
    else if(a>mid)
        return getsum(x<<1|1,mid+1,r,a,b);
    else return(getsum(x<<1,l,mid,a,b)+getsum(x<<1|1,mid+1,r,a,b))%mod;
}
inline int read()
{
    int x=0;
    bool f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    if(f)
        return -x;
    else return x;
}
int main()
{
    n=read();
    for(int i=1; i<=n; i++)
    {
        data[i].st=read(),data[i].v=read();
        seq[i]=data[i].st;
    }
    sort(&data[1],&data[n+1]);
    sort(&seq[1],&seq[n+1]);
    for(int i=1; i<=n; i++)
        data[i].st=lower_bound(&seq[1],&seq[n+1],data[i].st)-&seq[0];
    memset(mn,63,sizeof(mn));
    for(int i=1; i<=n; i++)
    {
        if(data[i].st<n)
            line[i].l=min(getmin(1,1,n,data[i].st+1,n),i);
        else line[i].l=i;
        modify(1,1,n,data[i].st,i);
    }
    memset(mx,0,sizeof(mx));
    for(int i=n; i>=1; i--)
    {
        if(data[i].st>1)
            line[i].r=max(getmax(1,1,n,1,data[i].st-1),i);
        else line[i].r=i;
        modify(1,1,n,data[i].st,i);
    }
    sort(&line[1],&line[n+1]);
    memset(sum,0,sizeof(sum));
    for(int i=n; i>=1; i--)
    {
        int now=0;
        if(line[i].r==n)
            now++;
        now+=getsum(1,1,n,1,min(line[i].r+1,n));
        if(now>=mod)
            now-=mod;
        modify(1,1,n,line[i].l,now);
        if(line[i].l==1)
            ans+=now;
        if(ans>=mod)
            ans-=mod;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 13568