#include <bits/stdc++.h>
using namespace std;
class Jora {
 public:
  int a;
  int b;
};
int myfunc(Jora A, Jora B) {
  if (A.a < B.a) return 1;
  if (A.a > B.a) return 0;
  return A.b < B.b;
}
Jora jrr[200200];
int n;
vector<int> ser;
map<int, int> taken;
map<int, vector<int> > mp;
int sss;
int cal() {
  map<int, int> val, ans;
  for (int i = 0; i < ser.size(); i++) {
    val[ser[i]] = 2000000000;
    ans[ser[i]] = 0;
  }
  int sum = 0;
  int cur = 0;
  int tim = 1;
  for (int i = 0; i < ser.size(); i++) {
    int to = ser[i];
    int uu = ((to - cur) + sum) % 1000000007;
    if (val[to] > uu) {
      val[to] = uu;
      ans[to] = tim;
    } else if (val[to] == uu) {
      ans[to] = (ans[to] + tim) % 1000000007;
    }
    int aa = val[to];
    int bb = ans[to];
    vector<int> &vvv = mp[to];
    for (int j : vvv) {
      if (val[j] > aa) {
        val[j] = aa;
        ans[j] = bb;
      } else if (val[j] == aa) {
        ans[j] = (ans[j] + bb) % 1000000007;
      }
    }
    sum = aa;
    cur = to;
    tim = bb;
  }
  int tot = 0;
  int value = 2000000000;
  map<int, int> mrk;
  for (int i = 1; i <= n; i++) {
    int u = jrr[i].a;
    if (mrk[u] != 1 && u > sss) {
      if (val[u] < value) {
        value = val[u];
        tot = ans[u];
      } else if (val[u] == value)
        tot = (tot + ans[u]) % 1000000007;
    }
    mrk[u] = 1;
  }
  return tot;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &jrr[i].a, &jrr[i].b);
    mp[jrr[i].b].push_back(jrr[i].a);
    if (taken[jrr[i].a] != 1) ser.push_back(jrr[i].a);
    if (taken[jrr[i].b] != 1) ser.push_back(jrr[i].b);
    taken[jrr[i].a] = 1;
    taken[jrr[i].b] = 1;
    sss = max(sss, jrr[i].b);
  }
  sort(ser.begin(), ser.end());
  printf("%d\n", cal());
  return 0;
}
