#include <bits/stdc++.h>
using namespace std;
const int module = int(1e9) + 7;
int n, id[200005], ID[200005];
pair<int, int> a[200005];
pair<long long, int> st[200005 * 4], d[200005];
bool cmp(int i, int j) { return a[i].second < a[j].second; }
int bins(int x) {
  int l = 1, r = n, tmp = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (a[id[mid]].second <= x) {
      tmp = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return tmp;
}
void update(int u, pair<long long, int> data, int l, int r, int i) {
  if (r < u || u < l) return;
  if (l == r) {
    st[i].first = data.first;
    st[i].second = data.second;
    return;
  }
  int mid = (l + r) / 2;
  update(u, data, l, mid, i * 2);
  update(u, data, mid + 1, r, i * 2 + 1);
  if (st[i * 2].first == st[i * 2 + 1].first) {
    st[i].first = st[i * 2].first;
    st[i].second = (st[i * 2].second + st[i * 2 + 1].second) % module;
  } else if (st[i * 2].first < st[i * 2 + 1].first) {
    st[i].first = st[i * 2].first;
    st[i].second = st[i * 2].second;
  } else {
    st[i].first = st[i * 2 + 1].first;
    st[i].second = st[i * 2 + 1].second;
  }
}
pair<long long, int> get(int u, int v, int l, int r, int i) {
  if (u > v) return make_pair(1000000000000000000LL, 0);
  if (r < u || v < l) return make_pair(1000000000000000000LL, 0);
  if (u <= l && r <= v) return st[i];
  int mid = (l + r) / 2;
  pair<long long, int> tmp, tmp1 = get(u, v, l, mid, i * 2),
                            tmp2 = get(u, v, mid + 1, r, i * 2 + 1);
  if (tmp1.first == tmp2.first) {
    tmp.first = tmp1.first;
    tmp.second = (tmp1.second + tmp2.second) % module;
  } else if (tmp1.first < tmp2.first) {
    tmp.first = tmp1.first;
    tmp.second = tmp1.second;
  } else {
    tmp.first = tmp2.first;
    tmp.second = tmp2.second;
  }
  return tmp;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].second, &a[i].first);
    id[i] = i;
  }
  sort(a + 1, a + n + 1);
  sort(id + 1, id + n + 1, cmp);
  for (int i = 1; i <= n; i++) ID[id[i]] = i;
  int res = 0;
  long long space_res = 1000000000000000000LL;
  for (int i = 1; i <= n; i++) {
    int pos = bins(a[i].first);
    pair<long long, int> data = get(1, pos, 1, n, 1);
    if (data.second == 0)
      d[i] = make_pair(a[i].first - a[i].second, 1);
    else
      d[i] = make_pair(a[i].first + data.first - a[i].second, data.second);
    update(ID[i], d[i], 1, n, 1);
    if (a[i].second > a[n].first) {
      if (d[i].first + a[i].second < space_res) {
        space_res = d[i].first + a[i].second;
        res = 0;
      }
      if (d[i].first + a[i].second == space_res) {
        res += d[i].second;
        res %= module;
      }
    }
  }
  printf("%d", res);
  return 0;
}
