#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
struct SegmentTree {
  vector<pair<long long, long long>> tree;
  long long n, root, size;
  SegmentTree(long long currSize) : n(currSize), root(1) {
    long long x = (long long)(ceil(log2(currSize)));
    size = 2 * (long long)pow(2, x);
    tree.resize(size, {1e18, 0});
  }
  pair<long long, long long> combine(const pair<long long, long long> &i,
                                     const pair<long long, long long> &j) {
    if (i.first < j.first) return i;
    if (i.first > j.first) return j;
    assert(i.first == j.first);
    return {i.first, (i.second + j.second) % mod};
  }
  void update(long long pos, pair<long long, long long> diff) {
    update(root, 0, n - 1, pos, diff);
  }
  void update(long long node, long long start, long long end, long long pos,
              pair<long long, long long> diff) {
    if (start > end || start > pos || end < pos) return;
    if (start >= pos && end <= pos) {
      tree[node] = diff;
      return;
    }
    long long mid = (start + end) / 2;
    update(2 * node, start, mid, pos, diff);
    update(2 * node + 1, mid + 1, end, pos, diff);
    tree[node] = combine(tree[2 * node], tree[2 * node + 1]);
  }
  pair<long long, long long> query(long long l, long long r) {
    return query(root, 0, n - 1, l, r);
  }
  pair<long long, long long> query(long long node, long long start,
                                   long long end, long long l, long long r) {
    if (r < start || end < l) return {1e18, 0};
    if (l <= start && end <= r) return tree[node];
    long long mid = (start + end) / 2;
    return combine(query(2 * node, start, mid, l, r),
                   query(2 * node + 1, mid + 1, end, l, r));
  }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> arr(n);
  for (long long i = 0; i < n; ++i) {
    cin >> arr[i].second >> arr[i].first;
  }
  sort(arr.begin(), arr.end());
  SegmentTree st(n + 2);
  for (long long i = n - 1; i >= 0; --i) {
    if (arr[i].second > arr.back().first) {
      st.update(i, {arr[i].first, 1});
    } else {
      long long start = i, end = n - 1, mid;
      while (start + 1 < end) {
        mid = start + (end - start) / 2;
        if (arr[i].second <= arr[mid].first) {
          end = mid;
        } else {
          start = mid;
        }
      }
      assert(end < n && arr[i].second <= arr[end].first);
      pair<long long, long long> res = st.query(end, n - 1);
      st.update(i, {res.first - (arr[i].second - arr[i].first), res.second});
    }
  }
  cout << st.query(0, n - 1).second << '\n';
}
