#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const long long MOD = 1000000007;
const long long INF = 10000000000000000;
const int inf = 1000000000;
template <class T>
T read(T& x) {
  char c;
  int flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag *= -1;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= flag;
  return x;
}
template <class T>
T pw(T a, T b) {
  T res = 1;
  while (b) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}
template <class T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <class T>
T exgcd(T a, T b, T& x, T& y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  T d = exgcd(b, a % b, x, y);
  T t = x;
  x = y;
  y = t - (a / b) * y;
  return d;
}
int n;
struct node_deg {
  int deg, down, id;
  node_deg() { deg = down = 0; }
} s[800005];
void degdown(int l, int r, int x) {
  if (l != r) {
    if (s[x].down) {
      s[x << 1].down += s[x].down;
      s[x << 1].deg += s[x].down;
      s[x << 1 | 1].down += s[x].down;
      s[x << 1 | 1].deg += s[x].down;
    }
  }
  s[x].down = 0;
}
void upd(int l, int r, int ls, int rs, int idx, int val) {
  degdown(l, r, idx);
  if (l >= ls && r <= rs) {
    s[idx].deg += val;
    s[idx].down += val;
    return;
  }
  if (l > rs || r < ls) return;
  int mid = (l + r) >> 1;
  upd(l, mid, ls, rs, idx << 1, val);
  upd(mid + 1, r, ls, rs, idx << 1 | 1, val);
  if (s[idx << 1].deg < s[idx << 1 | 1].deg)
    s[idx].deg = s[idx << 1].deg, s[idx].id = s[idx << 1].id;
  else
    s[idx].deg = s[idx << 1 | 1].deg, s[idx].id = s[idx << 1 | 1].id;
}
void build(int l, int r, int x) {
  if (l == r) {
    s[x].id = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, x << 1);
  build(mid + 1, r, x << 1 | 1);
  int idx = x;
  if (s[idx << 1].deg < s[idx << 1 | 1].deg)
    s[idx].deg = s[idx << 1].deg, s[idx].id = s[idx << 1].id;
  else
    s[idx].deg = s[idx << 1 | 1].deg, s[idx].id = s[idx << 1 | 1].id;
}
struct node_min {
  long long mn, cnt;
  node_min() {
    mn = INF;
    cnt = 0;
  }
} s2[800005];
void down(int l, int r, int x) {
  if (l != r) {
    if (s2[x << 1].mn > s2[x].mn) {
      s2[x << 1].mn = s2[x].mn;
      s2[x << 1].cnt = s2[x].cnt;
    } else if (s2[x << 1].mn == s2[x].mn)
      s2[x << 1].cnt = (s2[x << 1].cnt + s2[x].cnt) % MOD;
    if (s2[x << 1 | 1].mn > s2[x].mn) {
      s2[x << 1 | 1].mn = s2[x].mn;
      s2[x << 1 | 1].cnt = s2[x].cnt;
    } else if (s2[x << 1 | 1].mn == s2[x].mn)
      s2[x << 1 | 1].cnt = (s2[x << 1 | 1].cnt + s2[x].cnt) % MOD;
    s2[x].cnt = 0;
  }
}
void upd2(int l, int r, int ls, int rs, int idx, long long val, long long cnt) {
  down(l, r, idx);
  if (l >= ls && r <= rs) {
    if (val < s2[idx].mn) {
      s2[idx].mn = val;
      s2[idx].cnt = cnt;
    } else if (val == s2[idx].mn)
      s2[idx].cnt = (s2[idx].cnt + cnt) % MOD;
    return;
  }
  if (l > rs || r < ls) return;
  int mid = (l + r) >> 1;
  upd2(l, mid, ls, rs, idx << 1, val, cnt);
  upd2(mid + 1, r, ls, rs, idx << 1 | 1, val, cnt);
}
pair<long long, long long> query2(int l, int r, int pt, int idx) {
  down(l, r, idx);
  if (l == r) {
    return make_pair(s2[idx].mn, s2[idx].cnt);
  }
  int mid = (l + r) >> 1;
  if (pt > mid)
    return query2(mid + 1, r, pt, idx << 1 | 1);
  else
    return query2(l, mid, pt, idx << 1);
}
int query(int l, int r, int pt, int idx) {
  degdown(l, r, idx);
  if (l == r) return s[idx].deg;
  int mid = (l + r) >> 1;
  if (pt > mid)
    return query(mid + 1, r, pt, idx << 1 | 1);
  else
    return query(l, mid, pt, idx << 1);
}
pair<int, int> a[200005];
bool mark[200005];
bool mark2[200005];
int edge[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  build(1, n, 1);
  for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; ++i) {
    int pos = lower_bound(a + 1, a + n + 1, make_pair(a[i].second + 1, 0)) - a;
    pos--;
    if (pos < 1) {
      mark[i] = 1;
      continue;
    }
    edge[i] = pos;
    upd(1, n, 1, pos, 1, 1);
  }
  for (int i = 1; i <= n; ++i) {
    if (query(1, n, i, 1) == 0) {
      upd2(1, n, i, i, 1, 0, 1);
      mark2[i] = 1;
    }
  }
  long long mn = INF, cnt = 0;
  while (s[1].deg == 0 && s[1].id != 0) {
    int tar = s[1].id;
    upd(1, n, tar, tar, 1, inf);
    pair<long long, long long> val = query2(1, n, tar, 1);
    if (mark[tar]) {
      val.first = val.first + a[tar].second - a[tar].first;
      if (val.first < mn) {
        mn = val.first, cnt = val.second;
      } else if (val.first == mn)
        cnt = (cnt + val.second) % MOD;
    } else {
      upd(1, n, 1, edge[tar], 1, -1);
      if (!mark2[tar])
        upd2(1, n, 1, edge[tar], 1, val.first + a[tar].second - a[tar].first,
             val.second);
      else
        upd2(1, n, 1, edge[tar], 1, val.first + a[tar].second, val.second);
    }
  }
  cout << cnt << '\n';
}
