#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
int n, out[N], in[N];
int dp[N], cnt[N];
int p[N], q[N];
bool cmp1(int i, int j) { return out[i] < out[j]; }
bool cmp2(int i, int j) { return in[i] < in[j]; }
int main() {
  while (~scanf("%d", &n)) {
    int UP = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &out[i], &in[i]);
      p[i] = q[i] = i;
      UP = max(UP, in[i]);
    }
    sort(p + 1, p + 1 + n, cmp2);
    sort(q + 1, q + 1 + n, cmp1);
    int qq = 1;
    int mini = 0, cur = 1;
    int vol = 0x3f3f3f3f, ans = 0;
    for (int i = 1; i <= n; i++) {
      int pp = i;
      while (qq <= n && out[q[qq]] <= in[p[pp]]) {
        int id = q[qq++];
        int now = dp[id] - out[id];
        if (now < mini) mini = now, cur = 0;
        if (now == mini) cur = (cur + cnt[id]) % mod;
      }
      dp[p[pp]] = in[p[pp]] + mini;
      cnt[p[pp]] = cur;
      if (out[p[pp]] <= UP) continue;
      if (vol > dp[p[pp]]) vol = dp[p[pp]], ans = 0;
      if (vol == dp[p[pp]]) ans = (ans + cnt[p[pp]]) % mod;
    }
    printf("%d\n", ans);
  }
  return 0;
}
