#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

int n;
int b[N], k[N], idb[N], idk[N], rkb[N], rkk[N];
int lm[N], rm[N], dp[N];
vector<int> bob[N];

bool cmp1(int i, int j) {
  return b[i] < b[j];
}
bool cmp2(int i, int j) {
  return (k[i] != k[j])? k[i] < k[j] : b[i] < b[j];
}

namespace T {
  int t[N];
  void Upd(int x, int val) {
    for (; x <= n + 1; x += x & -x) {
      if ((t[x] += val) >= MOD) {
        t[x] -= MOD;
      }
    }
  }
  int Ask(int x) {
    int ret = 0;
    for (; x; x -= x & -x) {
      if ((ret += t[x]) >= MOD) {
        ret -= MOD;
      }
    }
    return ret;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &b[i], &k[i]);
    idb[i] = idk[i] = i;
  }

  sort(idb + 1, idb + 1 + n, cmp1);
  sort(idk + 1, idk + 1 + n, cmp2);
  for (int i = 1; i <= n; ++i) {
    rkb[idb[i]] = i;
    rkk[idk[i]] = i;
  }
  
  int mxk = 0;
  for (int i = 1; i <= n; ++i) {
    mxk = max(mxk, rkk[idb[i]]);
    rm[idb[i]] = mxk;
  }
  int mik = N;
  for (int i = n; i >= 1; --i) {
    mik = min(mik, rkk[idb[i]]);
    lm[idb[i]] = mik;
  }

  for (int i = 1; i <= n; ++i) {
    bob[rm[i]].push_back(lm[i]);
  }
  
  dp[0] = 1;
  T::Upd(1, 1);
  
  for (int i = 1; i <= n; ++i) {
    sort(bob[i].begin(), bob[i].end());
    for (int j = 0; j < bob[i].size(); ++j) {
      int p = bob[i][j] - 1;
      int sum = (T::Ask(i + 1) - T::Ask(p) + MOD) % MOD;
      (dp[i] += sum) %= MOD;
      T::Upd(i + 1, sum);
    }
  }

  printf("%d\n", dp[n]);
  
  return 0;
}
