#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }
int N;
int V[200000];
int L[200000], R[200000];
vector<int> G[200000];
int dp[200001];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<P> ps;
  vector<int> vs;
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    vs.pb(y);
    ps.pb(P(x, y));
  }
  sort(all(vs));
  sort(all(ps));
  rep(i, N) V[i] = index(vs, ps[i]._2);
  int cur = -1;
  rep(i, N) {
    cur = max(cur, V[i]);
    R[i] = cur;
  }
  cur = vs.size();
  for (int i=N-1; i>=0; i--) {
    cur = min(cur, V[i]);
    L[i] = cur;
  }
  rep(i, N-1) assert(L[i] <= L[i+1] && R[i] <= R[i+1]);
  rep(i, N) G[R[i]].pb(L[i]);

  dp[0] = 1;
  rep(r, N) {
    add(dp[r+1], dp[r]);
    for (int l : G[r]) add(dp[r+1], (dp[r+1] + MOD-(l>0?dp[l-1]:0))%MOD);
  }
  cout << (dp[N]+MOD-dp[N-1])%MOD << "\n";
  return 0;
}
