#include <bits/stdc++.h>
using namespace std;
const int N = (int)4e5 + 15;
const int MOD = (int)1e9 + 7;
const int inf = 0x3f3f3f3f;
struct Seg {
  int in, out;
  bool operator<(const Seg& b) const { return in < b.in; }
};
struct Data {
  int dpCom, mv;
};
Seg a[N];
Data tree[N << 2];
int mp[N], tag[N];
inline int addMod(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline Data merge(Data ls, Data rs) {
  Data ret;
  if (ls.mv != rs.mv) {
    ret = (ls.mv < rs.mv ? ls : rs);
  } else {
    ret.mv = ls.mv;
    ret.dpCom = addMod(ls.dpCom, rs.dpCom);
  }
  return ret;
}
inline void pushUp(int rt) {
  tree[rt] = merge(tree[rt << 1], tree[rt << 1 | 1]);
}
inline void build(int l, int r, int rt) {
  if (l == r) {
    tree[rt].dpCom = (l == 1);
    tree[rt].mv = l == 1 ? 0 : inf;
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  pushUp(rt);
}
inline void update(int pos, const Data& ret, int l, int r, int rt) {
  if (l == r) {
    tree[rt] = merge(ret, tree[rt]);
    return;
  }
  int m = (l + r) >> 1;
  if (pos <= m) {
    update(pos, ret, l, m, rt << 1);
  } else {
    update(pos, ret, m + 1, r, rt << 1 | 1);
  }
  pushUp(rt);
}
inline Data query(int qr, int l, int r, int rt) {
  if (r <= qr) {
    return tree[rt];
  }
  int m = (l + r) >> 1;
  Data ret = query(qr, l, m, rt << 1);
  if (m < qr) {
    ret = merge(ret, query(qr, m + 1, r, rt << 1 | 1));
  }
  return ret;
}
inline Data getAns(int pos, int l, int r, int rt) {
  if (l == r) {
    Data ret = tree[rt];
    ret.mv += mp[l];
    return ret;
  }
  int m = (l + r) >> 1;
  if (pos <= m) {
    return getAns(pos, l, m, rt << 1);
  } else {
    return getAns(pos, m + 1, r, rt << 1 | 1);
  }
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    memset(tag, 0, sizeof(tag));
    int mptot = 0;
    unordered_map<int, int> rmp;
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &a[i].out, &a[i].in);
      mp[++mptot] = a[i].out;
      mp[++mptot] = a[i].in;
    }
    mp[++mptot] = 0;
    build(1, mptot, 1);
    sort(a + 1, a + 1 + n);
    sort(mp + 1, mp + 1 + mptot);
    mptot = unique(mp + 1, mp + 1 + mptot) - mp - 1;
    for (int i = 1; i <= mptot; i++) {
      rmp[mp[i]] = i;
    }
    for (int i = 1; i <= n; i++) {
      tag[1]++;
      tag[rmp[a[i].in] + 1]--;
      Data tmp = query(rmp[a[i].in], 1, mptot, 1);
      Data t2 = {tmp.dpCom, tmp.mv + a[i].in - a[i].out};
      update(rmp[a[i].out], t2, 1, mptot, 1);
    }
    Data res = {0, inf};
    for (int i = 1; i <= mptot; i++) {
      tag[i] += tag[i - 1];
      if (!tag[i]) {
        res = merge(res, getAns(i, 1, mptot, 1));
      }
    }
    printf("%d\n", res.dpCom);
  }
}
