#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f  = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5, P = 1e9+7;
int n;
pair<int, int> p[N], h[N];
int f[N], ans;
int t[N], _[N];
void add(int x, int d) { for( ; x <= n; x += x&-x) t[x] = (t[x]+d)%P; }
int ask(int x) { int ret = 0; for( ; x > 0; x -= x&-x) ret = (ret+t[x])%P; return ret; }
int main()
{
    n = read();
    for(int i = 1; i <= n; ++i) 
    {
        int x = read(), v = read();
        p[i] = make_pair(x, v);
        _[i] = v;
    }
    sort(_+1, _+1+n), sort(p+1, p+1+n);
    for(int i = 1; i <= n; ++i) p[i].second = lower_bound(_+1, _+1+n, p[i].second)-_+1;
    for(int i = 1, f = 0; i <= n; ++i) f = max(f, p[i].second), h[i].first = f;
    for(int i = n, f = p[n].second; i; --i) f = min(f, p[i].second), h[i].second = f;
    h[++n] = make_pair(1, 1), sort(h+1, h+1+n), f[1] = 1, add(h[1].second, 1);
    for(int i = 2; i <= n; ++i) f[i] = (ask(h[i].first)-ask(h[i].second-2)+P)%P, add(h[i].first, f[i]);
    for(int i = n; i&&h[i].first == h[n].first; --i) ans = (ans+f[i])%P;
    printf("%d\n", ans);
    return 0;
}