#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U>
void _W(const pair<T, U> &x) {
  _W(x.first);
  putchar(' ');
  _W(x.second);
}
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
int MOD = 1e9 + 7;
void ADD(long long &x, long long v) {
  x = (x + v) % MOD;
  if (x < 0) x += MOD;
}
const int SIZE = 1e6 + 10;
vector<pair<int, int> > AA;
struct BIT {
  int _n;
  pair<long long, long long> _d[SIZE];
  void update(pair<long long, long long> &x, pair<long long, long long> v) {
    if (x.first > v.first)
      x = v;
    else if (x.first == v.first)
      ADD(x.second, v.second);
  }
  void init(int __n) {
    _n = __n;
    for (int i = (1); i <= (_n); ++i) _d[i] = {MOD, 0};
  }
  void ins(int x, pair<long long, long long> v) {
    for (; x <= _n; x += x & -x) {
      update(_d[x], v);
    }
  }
  pair<long long, long long> qq(int x) {
    pair<long long, long long> res = {MOD, 0};
    for (; x; x -= x & -x) {
      update(res, _d[x]);
    }
    return res;
  }
} bit;
int main() {
  int n;
  R(n);
  vector<int> d{-1, 0};
  for (int i = 0; i < (n); ++i) {
    int x, y;
    R(x, y);
    AA.push_back({y, x});
    d.push_back(x);
    d.push_back(y);
  }
  (sort(d.begin(), d.end()),
   d.resize(distance(d.begin(), unique(d.begin(), d.end()))));
  sort((AA).begin(), (AA).end());
  pair<long long, long long> an = {MOD, 0};
  bit.init(((int)(d).size()));
  bit.ins(1, {0, 1});
  for (int i = 0; i < (((int)(AA).size())); ++i) {
    int x = (lower_bound(d.begin(), d.end(), AA[i].first) - d.begin());
    int y = (lower_bound(d.begin(), d.end(), AA[i].second) - d.begin());
    pair<long long, long long> ret = bit.qq(x);
    if (AA[i].second > AA.back().first)
      bit.update(an, make_pair(ret.first + AA[i].first, ret.second));
    else {
      bit.ins(y, make_pair(AA[i].first + ret.first - AA[i].second, ret.second));
    }
  }
  W(an.second);
  return 0;
}
