#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200000;
int const modulo = 1000000007;

void normalize(std::vector<std::pair<int,int>> &v) {
  std::sort(v.begin(), v.end());
  for(int i = 0; i < v.size(); i++)
    v[i].first = 1 + i;
  for(int i = 0; i < v.size(); i++)
    std::swap(v[i].first, v[i].second);
  std::sort(v.begin(), v.end());
  for(int i = 0; i < v.size(); i++)
    v[i].first = 1 + i;
  for(int i = 0; i < v.size(); i++)
    std::swap(v[i].first, v[i].second);
}

class SegmentTree{
private:
  std::vector<int> aint;
  std::vector<int> lazy;
public:
  SegmentTree(int n) {
    aint.resize(1 + 4 * n);
    lazy.resize(1 + 4 * n);
  }
  void build(int node, int from, int to) {
    lazy[node] = 1;
    if(from < to) {
      int mid = (from + to) / 2;
      build(node * 2, from, mid);
      build(node * 2 + 1, mid + 1, to);
    }
  }

  void cleannode(int node, int from, int to) {
    if(from < to) {
      int mid = (from + to) / 2;
      lazy[node * 2] = 1LL * lazy[node * 2] * lazy[node] % modulo;
      lazy[node * 2 + 1] = 1LL * lazy[node * 2 + 1] * lazy[node] % modulo;
    }
    aint[node] = 1LL * aint[node] * lazy[node] % modulo;
    lazy[node] = 1;
  }
  
  void computenode(int node, int from, int to) {
    aint[node] = (aint[node * 2] + aint[node * 2 + 1]) % modulo;
  }

  void _add(int node, int from, int to, int x, int val) {
    if(from == to) {
      aint[node] = (aint[node] + val) % modulo;
    } else {
      int mid = (from + to) / 2;
      cleannode(node * 2, from, mid);
      cleannode(node * 2 + 1, mid + 1, to);
      if(x <= mid)
        _add(node * 2, from, mid, x, val);
      else
        _add(node * 2 + 1, mid + 1, to, x, val);
      computenode(node, from, to);
    }
  }

  void update(int node, int from, int to, int x, int y, int val) {
    if(from == x && to == y) {
      lazy[node] = 1LL * lazy[node] * val % modulo;
      cleannode(node, from, to);
    } else {
      int mid = (from + to) / 2;
      cleannode(node * 2, from, mid);
      cleannode(node * 2 + 1, mid + 1, to);
      if(x <= mid)
        update(node * 2, from, mid, x, MIN(mid, y), val);
      if(mid + 1 <= y)
        update(node * 2 + 1, mid + 1, to, MAX(mid + 1, x), y, val);
      computenode(node, from, to);
    }
  }
  int query(int node, int from, int to, int x, int y) {
    cleannode(node, from, to);
    if(from == x && to == y)
      return aint[node];
    else {
      int mid = (from + to) / 2;
      if(x <= mid && y <= mid)
        return query(node * 2, from, mid, x, y);
      else if(mid + 1 <= x && mid + 1 <= y)
        return query(node * 2 + 1, mid + 1, to, x, y);
      else
        return (query(node * 2, from, mid, x, mid) + 
                query(node * 2 + 1, mid + 1, to, mid + 1, y)) % modulo;
    }
  }

};

int affect[1 + nmax][2];
std::vector<int> event[1 + nmax];

int main() {
  int n;
  std::cin >> n;
  std::vector<std::pair<int,int>> v(n);
  for(int i = 0; i < n; i++)
    std::cin >> v[i].first >> v[i].second;
  normalize(v);
  std::sort(v.begin(), v.end()); 
  
  int smax = 0, smin = n;
  for(int i = 0; i < v.size(); i++) {
    smax = std::max(smax, v[i].second);
    affect[i][1] = smax;
  }
  for(int i = v.size() - 1; 0 <= i; i--) {
    smin = std::min(smin, v[i].second);
    affect[i][0] = smin;
  }
  for(int i = 0; i < v.size(); i++) {
    event[affect[i][1]].push_back(affect[i][0]);
  }

  int lim = n + 1;
  SegmentTree aint(lim);

  aint.build(1, 1, lim);
  aint._add(1, 1, lim, 1, 1);
  for(int i = 1;i <= n; i++) {
    for(int h = 0; h < event[i].size(); h++) {
      int l = event[i][h];
      if(1 < l)
        aint.update(1, 1, lim, 1, l - 1, 2);
      aint._add(1, 1, lim, i + 1, aint.query(1, 1, lim, l, i + 1));
    }
  }
  std::cout << aint.query(1, 1, lim, lim, lim);
  return 0;
}


Measured memory_bytes: 23480