#include <bits/stdc++.h>
using namespace std;

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}

int main(){
    int N;
    cin >> N;
    pair<int, int> XV[200000];
    int vs[200000];
    for(int i=0; i<N; i++){
        int x, v;
        cin >> x >> v;
        XV[i] = {x, v};
        vs[i] = v;
    }
    sort(XV, XV+N);
    sort(vs, vs+N);

    int V[200000], L[200000], R[200000];
    for(int i=0; i<N; i++) V[i] = lower_bound(vs, vs+N, XV[i].second) - vs;
    R[0] = V[0];
    for(int i=1; i<N; i++) R[i] = max(R[i-1], V[i]);
    L[N-1] = V[N-1];
    for(int i=N-2; i>=0; i--) L[i] = min(L[i+1], V[i]);

    static int64_t dp[200001];
    dp[0] = 1;
    int l = 0, r = 0;
    int64_t sum = 1;
    for(int i=0; i<N; i++){
        while(l < L[i]){
            add(sum, MOD - dp[l]);
            l++;
        }
        while(r <= R[i]){
            r++;
            add(sum, dp[r]);
        }
        add(dp[r], sum);
        add(sum, sum);
    }
    cout << dp[N] << endl;
    return 0;
}
