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

const int MOD = (int)1e9 + 7;

template<typename T>
struct segtree {
    int n, N;
    vector<pair<int, int> > a;
    vector<int> t;
    T f;

    segtree(vector<pair<int, int> > _a, T _f) {
        a = _a;
        f = _f;
        n = a.size();
        N = 1;
        while (N < n) N <<= 1;
        t.resize(N * 2);
        for (int i = 0; i < n; i++) t[N + i] = a[i].second;
        for (int i = N - 1; i >= 1; i--) t[i] = f(t[i * 2], t[i * 2 + 1]);
    }

    int get(int l, int r) {
        int res = a[l].second;
        l += N;
        r += N;

        while (l <= r) {
            if (l & 1) res = f(res, t[l]);
            if (!(r & 1)) res = f(res, t[r]);
            l = (l + 1) >> 1;
            r = (r - 1) >> 1;
        }
        return res;
    }
};

struct segtree2 {
    int n;
    vector<int> t;
    vector<int> p;

    segtree2(int _n) {
        n = _n;
        int N = 1;
        while (N < n) N <<= 1;
        N <<= 1;
        t.assign(N, 0);
        p.assign(N, 1);
    }

    void push(int v, int tl, int tr) {
        if (p[v] != 1) {
            t[v] = 1LL * t[v] * p[v] % MOD;
            if (tl != tr) {
                p[v * 2] = 1LL * p[v * 2] * p[v] % MOD;
                p[v * 2 + 1] = 1LL * p[v * 2 + 1] * p[v] % MOD;
            }
            p[v] = 1;
        }
    }

    int sum(int v, int tl, int tr, int l, int r) {
        push(v, tl, tr);
        if (l > r) return 0;
        if (l == tl && r == tr) return t[v];
        int tm = (tl + tr) >> 1;
        return (sum(v * 2, tl, tm, l, min(r, tm)) + sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r)) % MOD;
    }

    int sum(int l, int r) {
        l = max(l, 0);
        r = min(r, n - 1);
        return sum(1, 0, n - 1, l, r);
    }

    void mul(int v, int tl, int tr, int l, int r, int x) {
        push(v, tl, tr);
        if (l > r) return;
        if (l == tl && r == tr) {
            p[v] = x;
            push(v, tl, tr);
            return;
        }
        int tm = (tl + tr) >> 1;
        mul(v * 2, tl, tm, l, min(r, tm), x);
        mul(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, x);
        t[v] = (t[v * 2] + t[v * 2 + 1]) % MOD;
    }

    void mul(int l, int r, int x) {
        l = max(l, 0);
        r = min(r, n - 1);
        mul(1, 0, n - 1, l, r, x);
    }

    void add(int v, int tl, int tr, int x, int y) {
        push(v, tl, tr);
        if (tl == tr) {
            t[v] = (t[v] + y) % MOD;
            return;
        }
        int tm = (tl + tr) >> 1;
        if (x <= tm) add(v * 2, tl, tm, x, y);
        else add(v * 2 + 1, tm + 1, tr, x, y);
        t[v] = (t[v * 2] + t[v * 2 + 1]) % MOD;
    }

    void add(int x, int y) {
        if (x < 0 || x >= n) return;
        add(1, 0, n - 1, x, y);
    }
};

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif

    int n;
    while (scanf("%d", &n) == 1) {
        vector<pair<int, int> > a(n);
        for (int i = 0; i < n; i++) scanf("%d%d", &a[i].first, &a[i].second);
        sort(a.begin(), a.end());

        vector<int> vct;
        for (auto o : a) vct.push_back(o.second);
        sort(vct.begin(), vct.end());
        vct.resize(unique(vct.begin(), vct.end()) - vct.begin());
        for (auto &o : a) o.second = lower_bound(vct.begin(), vct.end(), o.second) - vct.begin();

        segtree<function<int(int, int)>> tmin(a, [&](int x, int y) { return min(x, y); });
        segtree<function<int(int, int)>> tmax(a, [&](int x, int y) { return max(x, y); });

        vector<pair<int, int> > ev;
        for (int i = 0; i < n; i++) {
            int mn = tmin.get(i, n - 1);
            int mx = tmax.get(0, i);
            //cerr << a[i].first << " " << a[i].second << "  " << mn << " " << mx << endl;
            ev.push_back(make_pair(mn, mx));
        }
        sort(ev.begin(), ev.end(), [&](pair<int, int> x, pair<int, int> y) {
            if (x.second != y.second) return x.second < y.second;
            return x.first < y.first;
        });

        segtree2 t(n + 1);
        t.add(0, 1);
        //cerr << n << endl;
        for (auto seg : ev) {
            //cerr << seg.first << " " << seg.second << endl;
            t.mul(0, seg.first - 1, 2);
            t.mul(seg.second + 1, n, 2);
            t.add(seg.second + 1, t.sum(seg.first, seg.second));
        }
        printf("%d\n", t.sum(n, n));
    }


#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}



Measured memory_bytes: 18136