#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5, mod = 1e9 + 7;
int n;
pair<int, int> a[M];
void inc(int& x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int h[M * 2], H;
unordered_map<int, int> U;
int pol[M * 2], cnt[M * 2];
void add(int p, pair<int, int> q) {
  for (int i = p; i <= H; i += i & -i) {
    if (pol[i] > q.first)
      pol[i] = q.first, cnt[i] = q.second;
    else if (pol[i] == q.first) {
      inc(cnt[i], q.second);
    }
  }
}
pair<int, int> sum(int p) {
  pair<int, int> res(mod, -1);
  for (int i = p; i > 0; i -= i & -i) {
    if (pol[i] < res.first)
      res.first = pol[i], res.second = cnt[i];
    else if (pol[i] == res.first)
      inc(res.second, cnt[i]);
  }
  return res;
}
int dp[M], num[M];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].second, &a[i].first);
    pol[i] = mod;
    h[++H] = a[i].first;
    h[++H] = a[i].second;
  }
  sort(h + 1, h + H + 1);
  H = unique(h + 1, h + H + 1) - h - 1;
  for (int i = 1; i <= H; i++) U[h[i]] = i;
  sort(a + 1, a + n + 1,
       [&](pair<int, int> x, pair<int, int> y) { return x.second < y.second; });
  for (int i = 1; i <= n; i++) {
    auto p = sum(U[a[i].first]);
    if (p.first >= 1e9) {
      dp[i] = a[i].first;
      num[i] = 1;
    } else {
      dp[i] = p.first + a[i].first;
      num[i] = p.second;
    }
    add(U[a[i].second], pair<int, int>(dp[i] - a[i].second, num[i]));
  }
  int min_val = mod, ans = 0;
  int last = 0;
  for (int i = n; i > 0; i--) {
    if (last < a[i].second) {
      if (dp[i] < min_val) {
        min_val = dp[i], ans = num[i];
      } else if (dp[i] == min_val) {
        inc(ans, num[i]);
      }
    }
    last = max(last, a[i].first);
  }
  printf("%d\n", ans);
}
