// Nurbakyt Madibek
// Look at my code! IT'S AWESOME

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)2e5 + 5;
const int mod = (int)1e9 + 7;

int n;
pi a[MAX_N];

bool cmp(const pi &a, const pi &b) {
    return a.s < b.s;
}

int l[MAX_N], r[MAX_N];

int mini[20][MAX_N], maxi[20][MAX_N];
int lg[MAX_N];

int getMaxi(int l, int r) {
    int i = lg[r - l + 1];
    return max(maxi[i][l], maxi[i][r - (1 << i) + 1]);
}

int getMini(int l, int r) {
    int i = lg[r - l + 1];
    return min(mini[i][l], mini[i][r - (1 << i) + 1]);
}

int p[MAX_N];

bool cmp2(int x, int y) {
    if (l[x] != l[y])
        return l[x] < l[y];
    return r[x] < r[y];
}

int dp[MAX_N];

void add(int &a, const int &b) {
    a += b;
    if (a >= mod)
        a -= mod;
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &a[i].f, &a[i].s);
    }
    sort(a + 1, a + n + 1, &cmp);
    for (int i = 1; i <= n; i++) {
        mini[0][i] = maxi[0][i] = a[i].f;
    }
    for (int it = 1; it < 20; it++) {
        for (int i = 1; i + (1 << it) - 1 <= n; i++) {
            mini[it][i] = min(mini[it - 1][i], mini[it - 1][i + (1 << (it - 1))]);
            maxi[it][i] = max(maxi[it - 1][i], maxi[it - 1][i + (1 << (it - 1))]);
        }
    }
    for (int i = 1, j = 0; i <= n; i++) {
        if ((1 << (j + 1)) == i)
            j++;
        lg[i] = j;
    }
    for (int i = 1; i <= n; i++) {
        int l = 1, r = i, mid = -1, best = -1;
        while(l <= r) {
            mid = (l + r) / 2;
            if (getMaxi(1, mid) >= a[i].f) {
                best = mid;
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        assert(best != -1);
        ::l[i] = best;
        
        l = i, r = n, mid = -1, best = -1;
        while(l <= r) {
            mid = (l + r) / 2;
            if (a[i].f >= getMini(mid, n)) {
                best = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        assert(best != -1);
        ::r[i] = best;
    }
    for (int i = 1; i <= n; i++)
        p[i] = i;
    sort(p + 1, p + n + 1, &cmp2);
    for (int i = 1; i + 1 <= n; i++)
        assert(l[p[i]] <= l[p[i + 1]] && r[p[i]] <= r[p[i + 1]]);
    
    p[0] = 0, p[n + 1] = n + 1;
    
    l[0] = r[0] = 0, l[n + 1] = r[n + 1] = n + 1;
    dp[n + 1] = 1;
    
    for (int i = n, j = n + 1, val = 1; i >= 0; i--) {
        while(l[p[j]] > r[p[i]] + 1) {
            add(val, mod - dp[j]);
            j--;
        }
        dp[i] = val;
        add(val, dp[i]);
    }
    
    printf("%d\n", dp[0]);
    return 0;
}


Measured memory_bytes: 36992