#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 500005
#define P 1000000007
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
#define pii pair<int,int>
using namespace std;

inline int add(int x, int y) {return x+y>=P?x+y-P:x+y;}
inline int sub(int x, int y) {return x>=y?x-y:x-y+P;}

int n, l[MAXN], r[MAXN], t[MAXN], f[MAXN];

struct Line {int k, b, id;} line[MAXN];
vector<Line> vec;

bool CMP1(Line x, Line y)
{
    if(x.k!=y.k) return x.k<y.k;
    return x.b<y.b;
}

bool CMP2(Line x, Line y)
{
    return x.b<y.b;
}

void update(int x, int y)
{
    for(; x<=n+1; x+=(x&-x)) t[x]=add(t[x], y);
}

int query(int x)
{
    int sum=0;
    for(; x; x-=(x&-x)) sum=add(t[x], sum);
    return sum;
}

int main()
{
    scanf("%d", &n);
    for(rint i=1; i<=n; ++i) scanf("%d%d", &line[i].b, &line[i].k);
    sort(line+1, line+n+1, CMP1);
    for(rint i=1; i<=n; ++i) line[i].id=i;
    sort(line+1, line+n+1, CMP2);
    l[n+1]=n+1;
    for(rint i=n; i>=1; --i) l[i]=min(l[i+1], line[i].id);
    for(rint i=1; i<=n; ++i) r[i]=max(r[i-1], line[i].id);
    update(1, 1);
    for(rint i=1; i<=n; ++i)
    {
        f[i]=sub(query(r[i]+1), query(l[i]-1));
        update(r[i]+1, f[i]);
    }
    printf("%d\n", sub(query(n+1), query(n)));
    return 0;
}