#include <bits/stdc++.h>
long long q_pow(long long x, long long n, long long mod) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = x * ret % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ret;
}
long long __gcd(long long x, long long y) {
  if (!y) return x;
  return __gcd(y, x % y);
}
long long getbit(long long now) {
  int cnt = 0;
  while (now) {
    cnt++;
    now -= (now) & (-now);
  }
  return cnt;
}
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
using namespace std;
const long long INF = 0x3f3f3f3f;
const int maxn = 1e6 + 60;
const int maxm = 200 * 200 + 10;
const double eps = 1e-7;
const double pi = acos(-1);
const int mod = 1e9 + 7;
int p[maxn], q[maxn];
int in[maxn], out[maxn];
int dp[maxn], f[maxn];
int main(int argc, char *argv[]) {
  if (argc == 2 && strcmp("-debug", argv[1]) == 0) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
  int n;
  int maxx = -INF, minn = INF;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &out[i], &in[i]);
    maxx = max(maxx, in[i]);
    p[i] = q[i] = i;
  }
  sort(p + 1, p + n + 1, [](int x, int y) { return in[x] < in[y]; });
  sort(q + 1, q + n + 1, [](int x, int y) { return out[x] < out[y]; });
  minn = 0;
  int now = 1;
  int j = 0;
  for (int i = 1; i <= n; i++) {
    int nowi = p[i];
    while (j < n and out[q[j + 1]] <= in[nowi]) {
      int nowj = q[j + 1];
      j++;
      if (f[nowj] - out[nowj] < minn)
        minn = f[nowj] - out[nowj], now = dp[nowj];
      else if (f[nowj] - out[nowj] == minn)
        now = (now + dp[nowj]) % mod;
    }
    f[nowi] = in[nowi] + minn;
    dp[nowi] = (dp[nowi] + now) % mod;
  }
  int ans = 1;
  minn = INF;
  for (int i = 1; i <= n; i++) cerr << dp[i] << endl;
  for (int i = 1; i <= n; i++) {
    if (out[i] <= maxx) continue;
    if (f[i] < minn)
      minn = f[i], ans = dp[i];
    else if (f[i] == minn)
      ans = (ans + dp[i]) % mod;
  }
  cout << ans << endl;
  return 0;
}
