#include<bits/stdc++.h>
#define int long long
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;
const LL rev2 = 500000004;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

struct MaxOp {
  const static LL INF = 1LL << 61;
  const static auto e = -INF;
  static LL apply(pll &f, LL v, LL w) {return f.X*v + f.Y;};
  static LL mergev(LL a, LL b) {return max(a, b);};
  static pll mergef(pll &f, pll &g) {return pll(f.X*g.X, f.X*g.Y+f.Y);};
};

struct MinOp {
  const static LL INF = 1LL << 61;
  const static auto e = INF;
  static LL apply(pll &f, LL v, LL w) {return f.X*v + f.Y;};
  static LL mergev(LL a, LL b) {return min(a, b);};
  static pll mergef(pll &f, pll &g) {return pll(f.X*g.X, f.X*g.Y+f.Y);};
};

// assign MOD := INF if raw values wanted
struct SumOp {
  const static auto e = 0LL;
  static LL apply(pll &f, LL v, LL w) {return (f.X*v + f.Y*w)%MOD;};
  static LL mergev(LL a, LL b) {
    LL ret = a+b; 
    while (ret >= MOD) ret -= MOD;
    return ret;
  };
  static pll mergef(pll &f, pll &g) {
    return pll((f.X*g.X)%MOD, (f.X*g.Y+f.Y)%MOD);
  };
};

template <class OP>
struct LazySeg {
  int size;
  vector<char> has_lazy;
  vector<LL> seg;
  vector<LL> width;
  vector<pll> lazy;

  // min

  // sum(mod -> INF)

  LazySeg() {}
  LazySeg(vector<LL> A) {
    Init(A);
  }

  void Init(vector<LL> A) {
    int n = A.size();
    size = 1;
    while (size < n) size *= 2;

    seg.resize(size);
    seg.insert(seg.end(), A.begin(), A.end());
    seg.resize(size*2);
    lazy.resize(size*2);
    has_lazy.resize(size*2);
    width.resize(size*2, 1);
    rrep(i, size) {
      seg[i] = OP::mergev(seg[i*2], seg[i*2+1]);
      width[i] = width[i*2] + width[i*2+1]; 
    }
  }

  void LazyPropagate(int k) {
    if (has_lazy[k]) {
      seg[k] = OP::apply(lazy[k], seg[k], width[k]);
      if (k < size) {
        rep(i, 2) {
          if (has_lazy[k*2+i]) {
            lazy[k*2+i] = OP::mergef(lazy[k], lazy[k*2+i]);
          } else {
            lazy[k*2+i] = lazy[k];
          }
          has_lazy[k*2+i] = true;
        }
      }
      has_lazy[k] = false;
    }
  }

  void Apply(int wishl, int wishr, int k, int watchl, int watchr, LL a, LL b) {
    if (wishr <= watchl || watchr <= wishl) {
      LazyPropagate(k);
      return;
    }

    if (wishl <= watchl && watchr <= wishr) {
      pll p(a, b);
      if (has_lazy[k]) {
        lazy[k] = OP::mergef(p, lazy[k]);
      } else {
        lazy[k] = p;
      }
      has_lazy[k] = true;
      LazyPropagate(k);
      return;
    }

    LazyPropagate(k);
    int mid = (watchl+watchr)/2;
    Apply(wishl, wishr, k*2, watchl, mid, a, b);
    Apply(wishl, wishr, k*2+1, mid, watchr, a, b);
    seg[k] = OP::mergev(seg[k*2], seg[k*2+1]);
  }

  void Apply(int wishl, int wishr, LL a, LL b) {
    return Apply(wishl, wishr, 1, 0, size, a, b);
  }

  LL Get(int wishl, int wishr, int k, int watchl, int watchr) {
    LL lval, rval;

    if (wishr <= watchl || watchr <= wishl) return OP::e;

    if (wishl <= watchl && watchr <= wishr) {
      LazyPropagate(k);
      return seg[k];
    }

    LazyPropagate(k);
    int mid = (watchl+watchr)/2;
    lval = Get(wishl, wishr, k*2, watchl, mid);
    rval = Get(wishl, wishr, k*2+1, mid, watchr);
    return OP::mergev(lval, rval);
  }

  LL Get(int wishl, int wishr) {
    return Get(wishl, wishr, 1, 0, size);
  }
};

typedef LazySeg<MaxOp> MaxSeg;
typedef LazySeg<MinOp> MinSeg;
typedef LazySeg<SumOp> SumSeg;

int N;
int M[214514];
vector<LL> vs;
vector<pll> ps;

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N;
  multiset<LL> lst, rst;
  rep(i, N) {
    LL x, v;
    cin >> x >> v;
    ps.eb(pll(x, v)); 
    rst.insert(v);
  }

  rep(i, N) {
    vs.eb(ps[i].Y);
  }
  sort(all(vs));
  vs.erase(unique(all(vs)), vs.end());

  auto GetIdx = [](LL v) {
    return lower_bound(all(vs), v) - vs.begin();
  };

  sort(all(ps));

  vector<pll> segs;
  rep(i, N) {
    LL l = ps[i].Y;
    LL r = ps[i].Y;
    if (!lst.empty()) {
      MX(r, *lst.rbegin());
    }

    if (!rst.empty()) {
      MN(l, *rst.begin());
    }
    lst.insert(ps[i].Y);
    rst.erase(rst.find(ps[i].Y));
    segs.eb(pll(l, r));
  }
  sort(all(segs));

  SumSeg dp;
  dp.Init(vector<LL>(N+10));

  dp.Apply(0, 1, 0, 1);
  rep(i, N) {
    int l = GetIdx(segs[i].X);
    int r = GetIdx(segs[i].Y)+1;
    dp.Apply(r, N+1, 2, 0);

    LL tot = dp.Get(l, r);
    dp.Apply(r, r+1, 1, tot);
  }

  LL ans = dp.Get(N, N+1);
  cout << ans << endl;
}



Measured memory_bytes: 40300