#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long maxn = (long long)2e6 + 5;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
long long T = 1;
pair<long long, long long> a[maxn];
long long num[maxn];
long long f[maxn], q[maxn], sum[maxn];
bool in[maxn];
void solve() {
  long long n;
  cin >> n;
  long long cnt = 0;
  for (long long i = 1; i <= n; ++i)
    cin >> a[i].second >> a[i].first, num[++cnt] = a[i].first,
                                      num[++cnt] = a[i].second;
  sort(num + 1, num + 1 + cnt);
  long long tot = unique(num + 1, num + 1 + cnt) - num - 1;
  long long minr = tot + 1, maxl = 0;
  for (long long i = 1; i <= n; ++i) {
    a[i].first = lower_bound(num + 1, num + 1 + tot, a[i].first) - num;
    a[i].second = lower_bound(num + 1, num + 1 + tot, a[i].second) - num;
    maxl = max(a[i].first, maxl);
    minr = min(a[i].second, minr);
  }
  sort(a + 1, a + n + 1);
  memset(f, inf, sizeof(f));
  memset(q, inf, sizeof(q));
  sum[0] = 1;
  q[0] = 0;
  for (long long i = 1; i <= n; ++i) {
    if (a[i].first > a[i - 1].first) {
      for (long long j = a[i - 1].first + 1; j <= a[i].first; ++j) {
        if (q[j] == q[j - 1])
          sum[j] = (sum[j - 1] + sum[j]) % mod;
        else if (q[j] > q[j - 1]) {
          q[j] = q[j - 1];
          sum[j] = sum[j - 1];
        }
      }
    }
    f[a[i].second] = q[a[i].first] + num[a[i].first];
    long long tmp = f[a[i].second] - num[a[i].second];
    if (tmp < q[a[i].second]) {
      q[a[i].second] = tmp;
      sum[a[i].second] = sum[a[i].first];
    } else if (tmp == q[a[i].second])
      sum[a[i].second] = (sum[a[i].second] + sum[a[i].first]) % mod;
  }
  long long minn = LLONG_MAX;
  for (long long i = n; i >= 1; --i)
    if (a[i].second > maxl) minn = min(minn, f[a[i].second]);
  long long ans = 0;
  for (long long i = n; i >= 1; --i) {
    if (a[i].second > maxl)
      if (!in[a[i].second] && f[a[i].second] == minn)
        ans = (ans + sum[a[i].second]) % mod;
    in[a[i].second] = true;
  }
  cout << ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  while (T--) solve();
  return 0;
}
