#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int n, maxin, Max, sl = 1, MAX = INT_MAX, SL;
pair<int, int> a[N], f[N];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    heap;
int main() {
  n = ({
    int x = 0;
    int c = getchar(), n = 0;
    for (; !isdigit(c); c = getchar()) n = (c == '-');
    for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
    n ? -x : x;
  });
  for (int i = 1, _b = n; i <= _b; ++i) {
    a[i] = {({
              int x = 0;
              int c = getchar(), n = 0;
              for (; !isdigit(c); c = getchar()) n = (c == '-');
              for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
              n ? -x : x;
            }),
            ({
              int x = 0;
              int c = getchar(), n = 0;
              for (; !isdigit(c); c = getchar()) n = (c == '-');
              for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
              n ? -x : x;
            })};
    swap(a[i].first, a[i].second);
    maxin = max(maxin, a[i].first);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1, _b = n; i <= _b; ++i) {
    while (!heap.empty() && heap.top().first <= a[i].first) {
      int j = heap.top().second;
      heap.pop();
      int c = f[j].first - a[j].second;
      if (c < Max) Max = c, sl = 0;
      if (c == Max) sl = (sl + f[j].second) % mod;
    }
    f[i] = {Max + a[i].first, sl};
    heap.push({a[i].second, i});
    if (a[i].second > maxin) {
      if (f[i].first < MAX) MAX = f[i].first, SL = 0;
      if (f[i].first == MAX) SL = (SL + f[i].second) % mod;
    }
  }
  cout << SL;
}
