#include <bits/stdc++.h>
#define fi first
#define sd second
#define ll long long
 
using namespace std;
 
const int maxn = 200200;
const int base = 1e9+7;
const ll inf = 1000000009;
 
pair<ll, int> p[maxn],q[maxn];
int n,l[maxn],r[maxn],id[maxn],t[maxn],f[maxn];
 
void update(int i,int k) {
    while (i<=n+1) {
        t[i] = (t[i]+k)%base;
        i+=(i&-i);
    }
}
 
int get(int i) {
    int res=0;
    while (i>0) {
        res = (res+t[i])%base;
        i-=(i&-i);
    }
    return res;
}
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
 //   freopen("in.txt","r",stdin);
    cin>>n;
    for (int i=1;i<=n;i++) {
        ll x;
        int v;
        cin>>x>>v;
        p[i] = make_pair(x,v);
    }
    sort(p+1,p+n+1);
    for (int i=1;i<=n;i++) {
        ll s;
        s = p[i].fi + inf*p[i].sd;
        q[i] = make_pair(s,i);
    }
    sort(q+1,q+n+1);
    //cout<<"fuck"<<endl;
    for (int i=1;i<=n;i++) id[q[i].sd] = i;
   // for (int i=1;i<=n;i++) cout<<id[i]<<" ";
    for (int i=1;i<=n;i++) {
        r[i] = id[i];
        if (i>1) r[i] = max(r[i],r[i-1]);
    }
    for (int i=n;i>=1;i--) {
        l[i] = id[i];
        if (i<n) l[i] = min(l[i],l[i+1]);
    }
    //cout<<"fuck"<<endl;
    update(1,1);
    //cout<<get(4)<<"fd"<<endl;
    for (int i=1;i<=n;i++) {
        //cout<<l[i]<<" "<<r[i];
        int sum = (get(r[i]+1) - get(l[i]-1) + base)%base;
        f[r[i]] = (f[r[i]] + sum)%base;
      //  cout<<sum<<endl;
        update(r[i]+1,sum);
    }
    cout<<f[n]<<endl;
}