#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
template <class T, class U>
inline void checkmin(T &x, U y) {
  if (y < x) x = y;
}
template <class T, class U>
inline void checkmax(T &x, U y) {
  if (y > x) x = y;
}
template <class T, class U>
inline bool ifmin(T &x, U y) {
  if (y < x) return x = y, true;
  return false;
}
template <class T, class U>
inline bool ifmax(T &x, U y) {
  if (y > x) return x = y, true;
  return false;
}
template <class T>
inline void sort(T &a) {
  sort(a.begin(), a.end());
}
template <class T>
inline void rsort(T &a) {
  sort(a.rbegin(), a.rend());
}
template <class T>
inline void reverse(T &a) {
  reverse(a.begin(), a.end());
}
template <class T, class U>
inline istream &operator>>(istream &str, pair<T, U> &p) {
  return str >> p.first >> p.second;
}
template <class T>
inline istream &operator>>(istream &str, vector<T> &a) {
  for (auto &i : a) str >> i;
  return str;
}
struct zet {
  long long val;
  zet(long long x = 0) {
    val = x % 1000000007;
    if (val < 0) val += 1000000007;
  }
  zet(long long a, long long b) {
    *this += a;
    *this /= b;
  }
  zet &operator+=(zet const &b) {
    val += b.val;
    if (val >= 1000000007) val -= 1000000007;
    return *this;
  }
  zet &operator-=(zet const &b) {
    val -= b.val;
    if (val < 0) val += 1000000007;
    return *this;
  }
  zet &operator*=(zet const &b) {
    val = (val * (long long)b.val) % 1000000007;
    return *this;
  }
  friend zet mypow(zet a, long long n) {
    zet res = 1;
    while (n) {
      if (n & 1) res *= a;
      a *= a;
      n >>= 1;
    }
    return res;
  }
  friend zet inv(zet a) { return mypow(a, 1000000007 - 2); }
  zet &operator/=(zet const &b) { return *this *= inv(b); }
  friend zet operator+(zet a, const zet &b) { return a += b; }
  friend zet operator-(zet a, const zet &b) { return a -= b; }
  friend zet operator-(zet a) { return 0 - a; }
  friend zet operator*(zet a, const zet &b) { return a *= b; }
  friend zet operator/(zet a, const zet &b) { return a /= b; }
  friend istream &operator>>(istream &stream, zet &a) {
    return stream >> a.val;
  }
  friend ostream &operator<<(ostream &stream, const zet &a) {
    return stream << a.val;
  }
  friend bool operator==(zet const &a, zet const &b) { return a.val == b.val; }
  friend bool operator!=(zet const &a, zet const &b) { return a.val != b.val; }
  friend bool operator<(zet const &a, zet const &b) { return a.val < b.val; }
};
struct node {
  long long mn = 3000000000000000007ll;
  zet sum = 0;
  node() {}
  node(long long x, zet c = 1) {
    mn = x;
    sum = c;
  }
};
node merge(node a, node b) {
  if (a.mn < b.mn) return a;
  if (b.mn < a.mn) return b;
  return node(a.mn, a.sum + b.sum);
}
struct Tree {
  static const long long n = 1 << 19;
  node t[2 * n + 5];
  void upd(long long r, long long x, zet c) {
    r += n;
    t[r] = merge(t[r], node(x, c));
    for (r >>= 1; r > 0; r >>= 1) t[r] = merge(t[r + r], t[r + r + 1]);
  }
  node get(long long l, long long r) {
    l += n;
    r += n + 1;
    node ans;
    while (l < r) {
      if (l & 1) ans = merge(ans, t[l++]);
      if (r & 1) ans = merge(ans, t[--r]);
      l >>= 1;
      r >>= 1;
    }
    return ans;
  }
} t;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout << fixed << setprecision(12);
  ;
  srand(235345);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > a(n);
  for (auto &i : a) {
    cin >> i.second >> i.first;
  }
  vector<long long> b;
  for (auto i : a) b.push_back(i.first), b.push_back(i.second);
  sort(b);
  b.resize(unique(b.begin(), b.end()) - b.begin());
  sort(a);
  vector<pair<long long, long long> > was = a;
  for (auto &i : a) {
    i.first = lower_bound(b.begin(), b.end(), i.first) - b.begin();
    i.second = lower_bound(b.begin(), b.end(), i.second) - b.begin();
  }
  vector<long long> mn(n);
  vector<zet> cnt(n);
  pair<long long, zet> answer = {3000000000000000007ll, 0};
  for (long long i = 0; i < n; ++i) {
    node ans = t.get(0, a[i].first);
    if (ans.mn == 3000000000000000007ll) {
      mn[i] = was[i].first - was[i].second;
      cnt[i] = 1;
    } else {
      mn[i] = ans.mn + was[i].first - was[i].second;
      cnt[i] = ans.sum;
    }
    t.upd(a[i].second, mn[i], cnt[i]);
    mn[i] += was[i].second;
    if (lower_bound(a.begin(), a.end(),
                    pair<long long, long long>(a[i].second, -1)) == a.end()) {
      if (ifmin(answer.first, mn[i])) answer.second = 0;
      if (answer.first == mn[i]) answer.second += cnt[i];
    }
  }
  cout << answer.second;
  return 0;
}
