#include <bits/stdc++.h>
using namespace std;
const int maxn = 212345;
const int MOD = 1e9 + 7;
int n, m;
pair<int, int> fen[maxn * 2];
inline int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
inline int lowbit(int x) { return x & -x; }
void add(pair<int, int> &a, pair<int, int> b) {
  if (a.first > b.first)
    a = b;
  else if (a.first == b.first)
    a.second = add(a.second, b.second);
}
void add(int x, pair<int, int> v) {
  while (x <= m) {
    add(fen[x], v);
    x += lowbit(x);
  }
}
pair<int, int> query(int x) {
  pair<int, int> ret = {MOD, 0};
  while (x > 0) {
    add(ret, fen[x]);
    x -= lowbit(x);
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  vector<int> val{-1, 0};
  vector<pair<int, int> > tab(n);
  for (int(i) = (0); (i) <= ((n)-1); (i)++) {
    scanf("%d%d", &tab[i].second, &tab[i].first);
    val.emplace_back(tab[i].first);
    val.emplace_back(tab[i].second);
  }
  sort((val).begin(), (val).end());
  (val).erase(unique((val).begin(), (val).end()), (val).end());
  sort((tab).begin(), (tab).end());
  pair<int, int> ans = {MOD, 0};
  m = val.size();
  for (int(i) = (1); (i) <= (m); (i)++) fen[i] = ans;
  add(1, {0, 1});
  for (auto now : tab) {
    int x = lower_bound((val).begin(), (val).end(), now.first) - val.begin();
    int y = lower_bound((val).begin(), (val).end(), now.second) - val.begin();
    auto cur = query(x);
    if (now.second > tab.back().first)
      add(ans, {cur.first + now.first, cur.second});
    else
      add(y, {now.first + cur.first - now.second, cur.second});
  }
  printf("%d", ans.second);
}
