#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 15;
const int mod = 1e9 + 7;
int add(int x, int y) {
  int ret = (x + y) % mod;
  if (ret < 0) {
    ret += mod;
  }
  return ret;
}
int mul(int x, int y) { return (long long)x * y % mod; }
int out[N], in[N], dp[N];
long long pre[N];
bool leaf[N], st[N];
pair<int, int> v[N];
long long mini[N], cc[N];
void solve() {
  int n;
  scanf("%d", &n);
  int maxIn = 0, minOut = 2e9;
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", &out[i], &in[i]);
    maxIn = max(maxIn, in[i]);
    minOut = min(minOut, out[i]);
    v[i] = make_pair(in[i], i);
  }
  for (int i = 1; i <= n; ++i) {
    if (out[i] > maxIn) {
      st[i] = true;
    }
    if (minOut > in[i]) {
      leaf[i] = true;
    }
  }
  sort(v + 1, v + n + 1);
  priority_queue<pair<long long, pair<long long, long long> >,
                 vector<pair<long long, pair<long long, long long> > >,
                 greater<pair<long long, pair<long long, long long> > > >
      pq;
  pair<long long, long long> R = make_pair(1e18, 0);
  for (int i = 1; i <= n; ++i) {
    int id = v[i].second;
    int iin = in[id];
    while (!pq.empty()) {
      if (pq.top().first <= iin) {
        pair<long long, long long> x = pq.top().second;
        pq.pop();
        if (x.first < R.first) {
          R = x;
        } else if (x.first == R.first) {
          R.second += x.second;
          R.second %= mod;
        }
      } else {
        break;
      }
    }
    if (leaf[id]) {
      mini[id] = in[id];
      cc[id] = 1;
    } else {
      mini[id] = R.first + in[id];
      cc[id] = R.second;
    }
    pq.push(make_pair(out[id], make_pair(mini[id] - out[id], cc[id])));
  }
  long long g = 1e18;
  for (int i = 1; i <= n; ++i) {
    if (st[i]) g = min(g, mini[i]);
  }
  long long ret = 0;
  for (int i = 1; i <= n; ++i) {
    if (st[i] && g == mini[i]) {
      ret += cc[i];
      ret %= mod;
    }
  }
  cout << ret << endl;
}
int main() { solve(); }
