#include <bits/stdc++.h>
using namespace std;
long long n;
int ans;
long long maxind;
const int MAXN = 4e5 + 5;
const long long MOD = 1e9 + 7;
pair<long long, long long> arr[MAXN];
pair<long long, long long> dp[MAXN];
pair<long long, long long> use[MAXN];
long long md = 1e18;
long long findidx(long long x, long long v) {
  long long l = 0;
  long long r = x;
  long long ans = 0;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (arr[mid].first <= v) {
      l = mid + 1;
      ans = mid;
    } else {
      r = mid - 1;
    }
  }
  return ans;
}
int main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i].first >> arr[i].second;
    maxind = max(maxind, arr[i].second);
  }
  sort(arr + 1, arr + 1 + n);
  dp[0] = make_pair(0, 1);
  for (long long i = 1; i <= n; i++) {
    dp[i] = dp[i - 1];
    long long idx = findidx(i, arr[i].second);
    long long mincost = dp[idx].first + arr[i].second - arr[i].first;
    if (mincost < dp[i].first) {
      dp[i] = make_pair(mincost, dp[idx].second);
    } else if (mincost == dp[i].first) {
      dp[i].second = dp[i].second + dp[idx].second;
      dp[i].second %= MOD;
    }
    use[i] = make_pair(mincost + arr[i].first, dp[idx].second);
    if (arr[i].first > maxind) {
      md = min(md, use[i].first);
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (use[i].first == md && arr[i].first > maxind) {
      ans = ans + use[i].second;
      ans %= MOD;
    }
  }
  cout << ans << endl;
}
