#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const long long mod = 1e9 + 7;
template <typename T>
void read(T &x) {
  int p = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  x *= p;
}
int a[N], tot;
int in[N], out[N];
map<int, int> sp;
int dis[N], nxt[N], va[N], to[N], fir[N], pnt;
void add_edge(int x, int y, int z) {
  nxt[++pnt] = fir[x];
  fir[x] = pnt;
  to[pnt] = y;
  va[pnt] = z;
}
int rd[N], nxt1[N], to1[N], fir1[N], ins[N], pnt1;
void add_edge1(int x, int y) {
  nxt1[++pnt1] = fir1[x];
  fir1[x] = pnt1;
  to1[pnt1] = y;
  rd[y]++;
}
queue<int> sp1;
void spfa(int p) {
  for (int i = 1; i <= tot + 2; i++) dis[i] = 2147483647;
  sp1.push(p);
  ins[p] = true;
  dis[p] = 0;
  while (!sp1.empty()) {
    p = sp1.front();
    sp1.pop();
    ins[p] = false;
    for (int j = fir[p]; j; j = nxt[j])
      if (dis[to[j]] > dis[p] + va[j]) {
        dis[to[j]] = dis[p] + va[j];
        if (!ins[to[j]]) sp1.push(to[j]), ins[to[j]] = true;
      }
  }
}
int vis[N], pos[N];
long long ans[N];
void tpsort(int s) {
  sp1.push(s);
  ans[s] = 1;
  while (!sp1.empty()) {
    s = sp1.front();
    sp1.pop();
    for (int j = fir1[s]; j; j = nxt1[j]) {
      ans[to1[j]] += ans[s];
      if (ans[to1[j]] >= mod) ans[to1[j]] -= mod;
      rd[to1[j]]--;
      if (!rd[to1[j]]) sp1.push(to1[j]);
    }
  }
}
int main() {
  int n, s, t;
  read(n);
  for (int i = 1; i <= n; i++) {
    read(out[i]);
    read(in[i]);
    a[i] = out[i];
    a[i + n] = in[i];
  }
  sort(a + 1, a + 2 * n + 1);
  for (int i = 1; i <= 2 * n; i++)
    if (a[i] != a[i - 1]) sp[a[i]] = ++tot, pos[tot] = a[i];
  s = tot + 1;
  t = tot + 2;
  for (int i = 1; i <= n; i++) {
    add_edge(sp[out[i]], sp[in[i]], 0);
    vis[sp[in[i]]] = 1;
  }
  for (int i = tot; i >= 1; i--) {
    if (vis[i]) break;
    add_edge(s, i, 0);
  }
  for (int i = tot; i > 1; i--) add_edge(i, i - 1, pos[i] - pos[i - 1]);
  add_edge(1, t, pos[1]);
  spfa(s);
  for (int i = 1; i <= t; i++)
    for (int j = fir[i]; j; j = nxt[j])
      if (dis[to[j]] == dis[i] + va[j]) add_edge1(i, to[j]);
  tpsort(s);
  cout << ans[t] << "\n";
  return 0;
}
