#include <bits/stdc++.h>
using namespace std;
int n, maxb;
int a[300005], b[300005], p[300005], q[300005], f[300005], g[300005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= (n); ++i)
    scanf("%d%d", a + i, b + i), p[i] = q[i] = i, maxb = max(maxb, b[i]);
  sort(p + 1, p + n + 1, [](int i, int j) { return b[i] < b[j]; });
  sort(q + 1, q + n + 1, [](int i, int j) { return a[i] < a[j]; });
  int j = 0;
  int mn = 0, gg = 1;
  for (int I = 1; I <= (n); ++I) {
    int i = p[I];
    while (j < n && a[q[j + 1]] <= b[i]) {
      int u = q[++j];
      if (f[u] - a[u] < mn) mn = f[u] - a[u], gg = 0;
      if (f[u] - a[u] == mn) gg = (gg + g[u]) % 1000000007;
    }
    f[i] = b[i] + mn;
    g[i] = gg;
  }
  mn = 0x7fffffff, gg = 0;
  for (int i = 1; i <= (n); ++i) {
    if (a[i] <= maxb) continue;
    if (f[i] < mn) mn = f[i], gg = 0;
    if (f[i] == mn) gg = (gg + g[i]) % 1000000007;
  }
  printf("%d\n", gg);
  return 0;
}
