#include <bits/stdc++.h>
using namespace std;
long long n, mod = 1e9 + 7ll, cont, maxi = 1000000000000ll, cont2, val[400005],
             ans, bestval = 1000000000000ll;
pair<long long, long long> dp[400005], num, ft[400005];
pair<int, int> v[400005];
map<int, int> ind;
vector<int> opz[400005], tmp;
void update(int pos, long long val, long long num) {
  for (int i = pos; i < 400005; i += (i & (-i))) {
    if (ft[i].first > val) {
      ft[i] = {val, num};
    } else {
      if (ft[i].first == val) ft[i].second += num;
      ft[i].second %= mod;
    }
  }
}
pair<long long, long long> query(int pos) {
  long long sol = maxi, solnum = 0;
  for (int i = pos; i > 0; i -= (i & (-i))) {
    if (ft[i].first < sol) {
      sol = ft[i].first;
      solnum = ft[i].second;
    } else {
      if (ft[i].first == sol) {
        solnum += ft[i].second;
        solnum %= mod;
      }
    }
  }
  return {sol, solnum};
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
    tmp.push_back(v[i].first);
    tmp.push_back(v[i].second);
  }
  sort(tmp.begin(), tmp.end());
  cont = 1;
  for (int i = 0; i < tmp.size(); i++) {
    if (i == 0 || tmp[i] != tmp[i - 1]) {
      ind[tmp[i]] = cont;
      val[cont] = tmp[i];
      cont++;
    }
  }
  for (int i = 0; i < n; i++) {
    opz[ind[v[i].first]].push_back(v[i].second);
  }
  for (int i = 0; i < 400005; i++) {
    sort(opz[i].begin(), opz[i].end());
    ft[i] = {maxi, 0};
  }
  update(1, maxi, 1);
  for (int i = 1; i < cont; i++) {
    cont2 = 0;
    if (opz[i].size() == 0) continue;
    dp[i].first = maxi;
    dp[i].second = 1;
    for (int j = 0; j < opz[i].size(); j++) {
      cont2++;
      if (j == opz[i].size() - 1 || opz[i][j] != opz[i][j + 1]) {
        num = query(ind[opz[i][j]]);
        num.first = num.first - (val[i] - opz[i][j]);
        num.second *= cont2;
        num.second %= mod;
        if (dp[i].first > num.first) {
          dp[i] = num;
        } else {
          if (dp[i].first == num.first) {
            dp[i].second += num.second;
            dp[i].second %= mod;
          }
        }
        cont2 = 0;
      }
    }
    update(i, dp[i].first, dp[i].second);
  }
  sort(v, v + n);
  reverse(v, v + n);
  for (int i = ind[v[0].first]; i > ind[v[0].second]; i--) {
    if (bestval > (dp[i].first - (maxi - val[i]))) {
      bestval = (dp[i].first - (maxi - val[i]));
      ans = dp[i].second;
    } else {
      if (bestval == (dp[i].first - (maxi - val[i]))) ans += dp[i].second;
      ans %= mod;
    }
  }
  cout << max(ans, 1ll) << endl;
  return 0;
}
