#include <bits/stdc++.h>

template <class T>
inline void read(T &res)
{
	res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	if (bo) res = ~res + 1;
}

template <class T>
inline T Min(const T &a, const T &b) {return a < b ? a : b;}

template <class T>
inline T Max(const T &a, const T &b) {return a > b ? a : b;}

const int N = 2e5 + 5, djq = 1e9 + 7;

int n, top, stk[N], le[N], ri[N], mx[N], f[N], s[N];

struct elem
{
	int x, v, id;
} a[N];

inline bool pmoc(elem a, elem b) {return a.v < b.v;}

inline bool comp(elem a, elem b) {return a.x < b.x;}

int main()
{
	read(n); int cur = n + 1;
	for (int i = 1; i <= n; i++) read(a[i].x), read(a[i].v);
	std::sort(a + 1, a + n + 1, comp);
	for (int i = 1; i <= n; i++) a[i].id = i;
	std::sort(a + 1, a + n + 1, pmoc);
	for (int i = n; i >= 1; i--) cur = Min(cur, a[i].id), le[a[i].id] = cur;
	cur = 1;
	for (int i = 1; i <= n; i++) cur = Max(cur, a[i].id), ri[a[i].id] = cur;
	f[0] = s[0] = 1;
	for (int i = 1; i <= n; i++) mx[ri[i]] = Max(mx[ri[i]], le[i]);
	for (int i = 1; i <= n; i++) mx[i] = Max(mx[i], mx[i - 1]);
	for (int i = 1; i <= n; i++)
		f[i] = (s[i - 1] - (mx[i - 1] ? s[mx[i - 1] - 1] : 0) + djq) % djq,
			s[i] = (s[i - 1] + f[i]) % djq;
	return std::cout << (s[n] - (mx[n] ? s[mx[n] - 1] : 0) + djq) % djq << std::endl, 0;
}