#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e16;
const long long mod = 1e9 + 7;
const int maxn = 2e5 + 5;
int n;
pair<long long, long long> mn[maxn << 2];
pair<long long, long long> dp[maxn];
int sz;
int b[maxn];
void build(int k, int lef, int rig) {
  mn[k] = pair<long long, long long>(inf, 0);
  if (lef == rig) return;
  int mid = (lef + rig) >> 1;
  build(k << 1, lef, mid);
  build(k << 1 | 1, mid + 1, rig);
}
pair<long long, long long> getmin(pair<long long, long long> f,
                                  pair<long long, long long> g) {
  if (f.first < g.first) return f;
  if (f.first > g.first) return g;
  return pair<long long, long long>(f.first, (f.second + g.second) % mod);
}
void update(int k, int lef, int rig, int pos, pair<long long, long long> f) {
  if (lef == rig) {
    mn[k] = getmin(mn[k], f);
    return;
  }
  int mid = (lef + rig) >> 1;
  if (pos <= mid)
    update(k << 1, lef, mid, pos, f);
  else
    update(k << 1 | 1, mid + 1, rig, pos, f);
  mn[k] = getmin(mn[k << 1], mn[k << 1 | 1]);
}
pair<long long, long long> query(int k, int lef, int rig, int l, int r) {
  if (l > r) return pair<long long, long long>(inf, 0);
  if (l <= lef && r >= rig) return mn[k];
  int mid = (lef + rig) >> 1;
  pair<long long, long long> ans = pair<long long, long long>(inf, 0);
  if (l <= mid) ans = getmin(ans, query(k << 1, lef, mid, l, r));
  if (r > mid) ans = getmin(ans, query(k << 1 | 1, mid + 1, rig, l, r));
  return ans;
}
int pre[maxn];
struct node {
  int in, out;
  bool operator<(const node &g) const {
    if (in == g.in) return out < g.out;
    return in < g.in;
  }
} a[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &a[i].out, &a[i].in), b[i] = a[i].out;
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  sz = unique(b + 1, b + n + 1) - b;
  for (int i = 1; i <= n; i++) {
    int pos = lower_bound(b + 1, b + sz, a[i].out) - b;
    pre[pos] = max(pre[pos], a[i].in);
    dp[i] = pair<long long, long long>(inf, 0);
  }
  build(1, 1, sz - 1);
  for (int i = 1; i < sz; i++) pre[i] = max(pre[i - 1], pre[i]);
  for (int i = 1; i <= n; i++) {
    int pos = upper_bound(b + 1, b + sz, a[i].in) - b - 1;
    int out = lower_bound(b + 1, b + sz, a[i].out) - b;
    if (pos == 0)
      update(1, 1, sz - 1, out,
             pair<long long, long long>(a[i].in - a[i].out, 1)),
          dp[i] = pair<long long, long long>(a[i].in, 1);
    else {
      int l = lower_bound(b + 1, b + sz, pre[pos]) - b;
      pair<long long, long long> ans = query(1, 1, sz - 1, l, pos);
      if (ans.first == inf)
        update(1, 1, sz - 1, out,
               pair<long long, long long>(a[i].in - a[i].out, 1)),
            dp[i] = pair<long long, long long>(a[i].in, 1);
      else
        update(1, 1, sz - 1, out,
               pair<long long, long long>(ans.first + a[i].in - a[i].out,
                                          ans.second)),
            dp[i] = pair<long long, long long>(ans.first + a[i].in, ans.second);
    }
  }
  pair<long long, long long> ans = pair<long long, long long>(inf, 0);
  for (int i = 1; i <= n; i++) {
    if (pre[sz - 1] >= a[i].out) continue;
    ans = getmin(ans, dp[i]);
  }
  printf("%lld\n", ans.second);
  return 0;
}
