#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 1e9 + 7;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
typedef std::pair<int, int> pr;
int n;
struct node {
	int x, v;
} a[maxn];
int rank[maxn];
inline int cmp0(const node & x,const node & y) { return x.v < y.v; }
inline int cmp1(const int & x,const int & y) { return a[x].x < a[y].x; }
int bit[maxn];
inline void add(int x,int v) {
	for(;x < maxn;x += x & -x)
		bit[x] += v - mod, bit[x] += bit[x] >> 31 & mod;
}
inline int qry(int x) {
	int ans = 0;
	for(;x;x &= x - 1)
		ans += bit[x] - mod, ans += ans >> 31 & mod;
	return ans;
}
pr seg[maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	rep(i, 1, n) {
		cin >> a[i].x >> a[i].v;
		rank[i] = i;
	}
	std::sort(a + 1,a + n + 1,cmp0);
	std::sort(rank + 1,rank + n + 1,cmp1);
	int max = 0, min = n;
	for(int i = 1;i <= n;++i) seg[rank[i]].second = max = std::max(max, rank[i]);
	for(int i = n;i >= 1;--i) seg[rank[i]].first = min = std::min(min, rank[i]);
	std::sort(seg + 1,seg + n + 1);
	add(n + 1, 1);
	for(int i = n;i >= 1;--i) {
		int s = qry(seg[i].second + 1) - qry(seg[i].first - 1);
		add(seg[i].first, s + (s >> 31 & mod));
	}
	cout << bit[1] << '\n';
}
