#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1, c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f ^= 1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return f ? x : -x;
}
pair<long long, int> merge(pair<long long, int> x, pair<long long, int> y) {
  if (x.first == y.first)
    return make_pair(x.first, (x.second + y.second) % 1000000007);
  else
    return min(x, y);
}
const int N = 1 << 18;
const long long linf = 0x3f3f3f3f3f3f3f3f;
struct SegT {
  pair<long long, int> t[N << 2];
  int siz;
  void init(int n) {
    siz = 1;
    while (siz <= n) siz <<= 1;
    for (int i = 0; i < (int)(siz << 1); ++i) t[i] = make_pair(linf, 0);
  }
  void upd(int x, pair<long long, int> v) {
    for (x += siz, t[x] = merge(t[x], v); x >>= 1;) {
      t[x] = merge(t[x << 1], t[x << 1 | 1]);
    }
  }
  pair<long long, int> qry(int l, int r) {
    pair<long long, int> ans(linf, 0);
    for (l += siz, r += siz; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ans = merge(ans, t[l++]);
      if (r & 1) ans = merge(ans, t[--r]);
    }
    return ans;
  }
} segt;
int n, in[N], out[N], id[N];
int m, vx[N << 1];
int m1, vy[N];
int getid(int x) { return lower_bound(vx, vx + m, x) - vx; }
bool cmp(int a, int b) {
  return in[a] != in[b] ? in[a] < in[b] : out[a] < out[b];
}
int main() {
  n = read();
  for (int i = 0; i < (int)(n); ++i) out[i] = read(), in[i] = read(), id[i] = i;
  for (int i = 0; i < (int)(n); ++i) vx[m++] = in[i];
  for (int i = 0; i < (int)(n); ++i) vx[m++] = out[i];
  sort(vx, vx + m);
  m = unique(vx, vx + m) - vx;
  sort(id, id + n, cmp);
  for (int i = 0; i < (int)(n); ++i) vy[m1++] = in[i];
  sort(vy, vy + m1);
  m1 = unique(vy, vy + m1) - vy;
  segt.init(m);
  int ps = 0;
  pair<long long, int> ans(linf, 0);
  for (int ii = 0; ii < (int)(n); ++ii) {
    int i = id[ii];
    pair<long long, int> p = segt.qry(0, getid(in[i]) + 1);
    if (p.first >= linf) p = make_pair(0, 1);
    p.first += in[i] - out[i];
    segt.upd(getid(out[i]), p);
    if (lower_bound(vy, vy + m1, out[i]) == vy + m1)
      ans = merge(ans, make_pair(p.first + out[i], p.second));
  }
  printf("%d\n", ans.second);
  return 0;
}
