#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
using namespace std;
template <typename T>
void uin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T>
void uax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
const int N = 228228;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 228;
int mod(int x) {
  x %= MOD;
  if (x < 0) x += MOD;
  return x;
}
void add(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  if (a < 0) a += MOD;
}
map<int, int> t[N * 2];
int NNN;
void init(int _n) { NNN = _n; }
void update(int i, int sum, int cnt) {
  --i;
  for (; i < NNN; i |= (i + 1)) {
    add(t[i][sum], cnt);
    while (!t[i].empty() && t[i].begin()->second == 0) t[i].erase(t[i].begin());
  }
}
pair<int, int> get(int i) {
  --i;
  pair<int, int> res;
  res.first = INF;
  res.second = 0;
  pair<int, int> L, R;
  for (; i >= 0; i = (i & (i + 1)) - 1) {
    if (t[i].empty()) continue;
    L = res;
    R = *t[i].begin();
    res.first = min(L.first, R.first);
    res.second = 0;
    if (L.first == res.first) add(res.second, L.second);
    if (R.first == res.first) add(res.second, R.second);
  }
  return res;
}
int in[N], out[N];
int sum[N], cnt[N];
int go[N], more[N];
int sin228[N], sout[N];
vector<int> over[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > v;
  vector<int> crd;
  for (int i = 1; i <= n; ++i) {
    cin >> out[i] >> in[i];
    v.emplace_back(out[i], in[i]);
    crd.push_back(in[i]), crd.push_back(out[i]);
  }
  sort(crd.begin(), crd.end());
  crd.erase(unique(crd.begin(), crd.end()), crd.end());
  sort(v.begin(), v.end());
  for (int i = 1; i <= n; ++i) {
    out[i] = v[i - 1].first;
    in[i] = v[i - 1].second;
    sout[i] = lower_bound(crd.begin(), crd.end(), out[i]) - crd.begin() + 1;
    sin228[i] = lower_bound(crd.begin(), crd.end(), in[i]) - crd.begin() + 1;
  }
  init((int)crd.size() + 3);
  int ptr = 2;
  for (int i = 1; i <= n; ++i) {
    uax(ptr, i + 1);
    while (ptr <= n && in[ptr] < out[i]) ++ptr;
    more[i] = ptr;
  }
  for (int i = 1; i <= n; ++i) {
    if (more[i] == n + 1)
      go[i] = n + 1;
    else
      go[i] = more[more[i]];
    over[go[i]].push_back(i);
  }
  multiset<int> s;
  map<int, int> count228;
  for (int i = 1; i <= n; ++i) {
    sum[i] = INF;
    if (out[1] > in[i]) {
      sum[i] = in[i] - out[i];
      cnt[i] = 1;
    }
    for (int x : over[i]) {
      update(sout[x], sum[x], -cnt[x]);
    }
    pair<int, int> kek = get(sin228[i]);
    if (kek.first + in[i] - out[i] < sum[i]) {
      sum[i] = kek.first + in[i] - out[i];
      cnt[i] = kek.second;
    }
    update(sout[i], sum[i], cnt[i]);
  }
  int msum = INF;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (more[i] != n + 1) continue;
    if (sum[i] + out[i] < msum) {
      msum = sum[i] + out[i];
      ans = cnt[i];
    } else if (sum[i] + out[i] == msum) {
      add(ans, cnt[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
