#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 100 * 1000 + 5;
const int off = 1 << 18;
const int inf = 1e9 + 10;
const int MOD = 1e9 + 7;
int in[maxn], out[maxn], cnt[maxn], b[maxn], t[2 * off];
map<int, vector<pair<int, int>>> M;
int query(int w, int p, int k, int beg, int end) {
  if (p == beg && k == end) return t[w];
  int mid = (beg + end) / 2;
  if (k <= mid) return query(w * 2, p, k, beg, mid);
  if (p >= mid) return query(w * 2 + 1, p, k, mid, end);
  return min(query(w * 2, p, mid, beg, mid),
             query(w * 2 + 1, mid, k, mid, end));
}
int count(int p, int k, int val) {
  vector<pair<int, int>> &v = M[val];
  assert(v.size() > 0);
  int beg = -1, mid, end = v.size() - 1;
  while (beg + 1 < end) {
    mid = (beg + end) / 2;
    if (v[mid].first >= p)
      end = mid;
    else
      beg = mid;
  }
  int from = end;
  beg = 0;
  end = v.size();
  while (beg + 1 < end) {
    mid = (beg + end) / 2;
    if (v[mid].first <= k)
      beg = mid;
    else
      end = mid;
  }
  int fin = beg;
  int res = v[fin].second;
  if (from > 0) res = (res + MOD - v[from].second) % MOD;
  return res;
}
void update(int i, int c, int val) {
  if (M[val].empty())
    M[val].push_back(make_pair(i, c));
  else
    M[val].push_back(make_pair(i, (c + M[val].back().second) % MOD));
  i += off;
  t[i] = val;
  i /= 2;
  while (i > 0) {
    t[i] = min(t[i * 2], t[i * 2 + 1]);
    i /= 2;
  }
}
int main() {
  for (int i = 0; i < (2 * off); ++i) t[i] = inf;
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < (n); ++i) cin >> v[i].first >> v[i].second;
  sort(v.begin(), v.end());
  for (int i = 0; i < (n); ++i) {
    in[i] = v[i].second;
    out[i] = v[i].first;
  }
  for (int i = 0; i < (n); ++i) {
    int beg = -1, mid, end = i;
    while (beg + 1 < end) {
      mid = (beg + end) / 2;
      if (out[mid] <= in[i])
        beg = mid;
      else
        end = mid;
    }
    b[i] = beg;
    int a = 0;
    if (beg != -1) a = b[beg] + 1;
    int x = 0;
    if (a <= b[i]) x = query(1, a, b[i] + 1, 0, off);
    int y = x + in[i] - out[i];
    if (x == 0)
      cnt[i] = 1;
    else
      cnt[i] = count(a, b[i], x);
    update(i, cnt[i], y);
  }
  int W = in[0];
  for (int i = 0; i < (n); ++i) W = max(W, in[i]);
  vector<int> alive;
  for (int i = 0; i < (n); ++i)
    if (out[i] > W) alive.push_back(i);
  assert(alive.size() > 0);
  int E = t[off + alive[0]] + out[alive[0]];
  for (int i = 0; i < (alive.size()); ++i)
    E = min(E, t[off + alive[i]] + out[alive[i]]);
  int res = 0;
  for (int i = 0; i < (alive.size()); ++i) {
    if (t[off + alive[i]] + out[alive[i]] == E) {
      res = (res + cnt[alive[i]]) % MOD;
    }
  }
  cout << res << endl;
  return 0;
}
