#include <bits/stdc++.h>
using namespace std;
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
const long long MAXN = 1e6 + 10;
const long long INF = 8e18;
const long long MOD = 1e9 + 7;
map<long long, vector<pair<long long, long long>>> mp;
long long n, dp[MAXN], pref_mn[MAXN], cnt[MAXN];
vector<pair<long long, long long>> v;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  v.resize(n);
  v.push_back({0, -INF});
  for (long long i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
  sort((v).begin(), (v).end());
  mp[0].push_back({0, 1});
  for (long long i = 1; i <= n; i++) {
    long long score = v[i].second - v[i].first;
    long long L = 0, R = i - 1;
    while (L < R) {
      long long mid = (L + R + 1) / 2;
      if (v[mid].first <= v[i].second)
        L = mid;
      else
        R = mid - 1;
    }
    long long score_p = pref_mn[L];
    dp[i] = score + score_p;
    if (!mp[score_p].empty()) {
      auto it = upper_bound((mp[score_p]).begin(), (mp[score_p]).end(),
                            make_pair(L, INF));
      if (it != mp[score_p].begin()) {
        it--;
        cnt[i] = it->second;
      }
    }
    long long pb_val = cnt[i];
    if (!mp[dp[i]].empty()) pb_val += mp[dp[i]].back().second;
    mp[dp[i]].push_back({i, pb_val % MOD});
    pref_mn[i] = min(pref_mn[i - 1], dp[i]);
  }
  long long ans = 0, mn_found = INF, mx_in = 0;
  for (long long i = 1; i <= n; i++) dp[i] += v[i].first;
  for (long long i = n; i > 0; i--) {
    if (v[i].first <= mx_in) break;
    if (dp[i] > mn_found) {
      mx_in = max(v[i].second, mx_in);
      continue;
    }
    if (dp[i] < mn_found) {
      mn_found = dp[i];
      ans = 0;
    }
    ans += cnt[i];
    ans %= MOD;
    mx_in = max(mx_in, v[i].second);
  }
  cout << ans % MOD << '\n';
  return 0;
}
