#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
long long inf = 1e9 + 1;
const int mod = 1e9 + 7;
long long a[N], dp[N], cnt[N], m[N], ct[N], in[N], out[N], mxin[N], v = 1;
int ps[N];
void als(int i, int j, int x) {
  i += v - 2;
  m[i] = j;
  ct[i] = x;
  while (i > 0) {
    i = (i - 1) / 2;
    m[i] = min(m[2 * i + 1], m[2 * i + 2]);
    ct[i] = 0;
    if (m[i] == m[2 * i + 1]) ct[i] += ct[2 * i + 1];
    if (m[i] == m[2 * i + 2]) ct[i] += ct[2 * i + 2];
    ct[i] %= mod;
  }
}
long long get(int v, int vl, int vr, int l, int r, int &tm) {
  if (l <= vl && vr <= r) {
    tm = m[v];
    return ct[v];
  } else if (l >= vr || vl >= r) {
    tm = inf;
    return 0;
  } else {
    int a, b, c, d;
    a = get(2 * v + 1, vl, (vl + vr) / 2, l, r, b);
    c = get(2 * v + 2, (vl + vr) / 2, vr, l, r, d);
    tm = min(b, d);
    int cnt = 0;
    if (tm == b) cnt += a;
    if (tm == d) cnt += c;
    return cnt % mod;
  }
}
vector<pair<long long, long long> > vp;
int main() {
  int i, j, k, n, pin, pout;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  v = 1;
  while (v < n) v *= 2;
  for (i = 0; i < n; ++i) {
    cin >> pout >> pin;
    vp.push_back({pout, pin});
  }
  sort(vp.begin(), vp.end());
  long long ans_cnt = 0, ans_ps = inf;
  for (i = 0; i < vp.size(); ++i) {
    out[i + 1] = vp[i].first;
    in[i + 1] = vp[i].second;
    mxin[i + 1] = max(mxin[i], in[i + 1]);
  }
  for (i = 1; i <= n; ++i) {
    int l1 = 0, r1 = i;
    while (r1 - l1 > 1) {
      int mid = (l1 + r1) / 2;
      if (out[mid] > in[i])
        r1 = mid;
      else
        l1 = mid;
    }
    int l2 = 1, r2 = i;
    while (r2 - l2 > 1) {
      int mid = (l2 + r2) / 2 - 1;
      if (out[mid] <= mxin[l1])
        l2 = mid + 1;
      else
        r2 = mid + 1;
    }
    cnt[i] = get(0, 1, v + 1, l2, l1 + 1, ps[i]);
    if (ps[i] == inf) {
      ps[i] = 0;
      cnt[i] = 1;
    }
    if (out[i] > mxin[n])
      if (ans_ps > ps[i] + in[i]) {
        ans_ps = ps[i] + in[i];
        ans_cnt = cnt[i];
      } else if (ans_ps == ps[i] + in[i])
        ans_cnt += cnt[i];
    ps[i] += in[i] - out[i];
    als(i, ps[i], cnt[i]);
  }
  cout << ans_cnt % mod;
}
