// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 4e5 + 5, S = 20 * N, mod = (int) 1e9 + 7;
int n, dp[N], pre[N], av[N], suf[N], cl[S], cr[S], seg[S], cnt;
vector<int> va;
pair<int, int> sr[N];
int build(int b = 0, int e = n) {
	int v = cnt++;
	if (b + 1 == e) {
		return v;	
	}
	int m = b + e >> 1;
	cl[v] = build(b, m);
	cr[v] = build(m, e);
	return v;
}
int update(int pos, int x, int id, int b = 0, int e = n) {
	int v = cnt++;
	cl[v] = cl[id];
	cr[v] = cr[id];
	seg[v] = seg[id];
	if (b + 1 == e) {
		seg[v] += x;
		return v;
	}
	int m = b + e >> 1;
	if (pos < m) 
		cl[v] = update(pos, x, cl[id], b, m);
	else
		cr[v] = update(pos, x, cr[id], m, e);
	seg[v] = seg[cl[v]] + seg[cr[v]];
	return v;
}
int query(int i, int j, int v, int b = 0, int e = n) {
	if (i >= e || b >= j) return 0;
	if (i <= b && e <= j) return seg[v];
	int m = b + e >> 1;
	return query(i, j, cl[v], b, m) + query(i, j, cr[v], m, e);
}
int root[N], sum[N], rev[N], ord[N];
map<int, int> pl;
int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for (int j = 0; j < n; ++j)
		cin >> sr[j].first >> sr[j].second;
	sort(sr, sr + n);
	av[0] = (int) -1e9;
	for (int j = 1; j < n + 1; ++j)
		av[j] = sr[j - 1].second;
	++n;
	av[n] = 1e9 + 1;
	++n;
	for (int j = 0; j < n; ++j) va.pb(av[j]);
	sort(ALL(va));
	for (int j = 0; j < n; ++j) pl[va[j]] = j;
	for (int j = 0; j < n; ++j) av[j] = pl[av[j]], rev[av[j]] = j;
	root[0] = build();
	for (int j = 0; j < n; ++j) {
		root[j + 1] = update(rev[j], 1, root[j]);
		ord[j] = j;	
	}
	suf[n] = av[n - 1];
	for (int j = n - 1; j >= 0; --j)
		suf[j] = min(suf[j + 1], av[j]);
	pre[0] = av[0];
	for (int j = 0; j < n; ++j)
		pre[j + 1] = max(pre[j], av[j]);
	dp[0] = 1;
	sum[1] = 1;
	for (int j = 1; j < n; ++j) {
		int bl = -1, br = j - 1;
		while (bl < br - 1) {
			int bm = bl + br >> 1;
			int l = pre[bm + 1], r = suf[j];	
			int val = query(bm, j, root[ord[r]]) - query(bm, j, root[ord[l] + 1]);
			if (val <= 0) {
				br = bm;
			} else {
				bl = bm;
			}
		}
		dp[j] = (sum[j] - sum[br] + mod) % mod;
		
/*		for (int last = 0; last < j; ++last) {
			int l = pre[last + 1], r = suf[j], flag = 1;
			for (int k = last + 1; k < j; ++k)
				if (av[k] > l && av[k] < r)
					flag = 0;
			
			if (flag) {
				dp[j] = (dp[j] + dp[last]) % mod;
				cout << " hello " << j << ' ' << last << endl;	
			}
		}
		*/
		
		sum[j + 1] = (sum[j] + dp[j]) % mod;
	}
	cout << dp[n - 1] << endl;
	
}





Measured memory_bytes: 77300