#include <cstdio>
#include <algorithm>
struct tok
{
	int x, v;
}
p[200001];
int N, a[200001], H[200001], MIN[524288], MAX[524288];
struct seg
{
	int l, r;
}
q[200001];
void Put(int x, int w)
{
	int p = 1, l = 1, r = N;
	while (l < r)
	{
		int m = l + r >> 1;
		if (x <= m)
			p <<= 1, r = m;
		else
			p = p << 1 | 1, l = m + 1;
	}
	MIN[p] = MAX[p] = w;
	while (p > 1)
	{
		p >>= 1;
		MIN[p] = std::min(MIN[p << 1], MIN[p << 1 | 1]);
		MAX[p] = std::max(MAX[p << 1], MAX[p << 1 | 1]);
	}
}
int Min(int p, int l, int r, int L, int R)
{
	if (L <= l && r <= R)
		return MIN[p];
	int m = l + r >> 1;
	if (R <= m)
		return Min(p << 1, l, m, L, R);
	if (L > m)
		return Min(p << 1 | 1, m + 1, r, L, R);
	return std::min(Min(p << 1, l, m, L, R), Min(p << 1 | 1, m + 1, r, L, R));
}
int Max(int p, int l, int r, int L, int R)
{
	if (L <= l && r <= R)
		return MAX[p];
	int m = l + r >> 1;
	if (R <= m)
		return Max(p << 1, l, m, L, R);
	if (L > m)
		return Max(p << 1 | 1, m + 1, r, L, R);
	return std::max(Max(p << 1, l, m, L, R), Max(p << 1 | 1, m + 1, r, L, R));
}
const long long MOD = 1000000007;
long long SUM[524288], MUL[524288];
void build(int p, int l, int r)
{
	SUM[p] = l == 0;
	MUL[p] = 1;
	if (l < r)
	{
		int m = l + r >> 1;
		build(p << 1, l, m);
		build(p << 1 | 1, m + 1, r);
	}
}
inline void down(int p)
{
	if (MUL[p] != 1)
	{
		SUM[p << 1] = SUM[p << 1] * MUL[p] % MOD;
		MUL[p << 1] = MUL[p << 1] * MUL[p] % MOD;
		SUM[p << 1 | 1] = SUM[p << 1 | 1] * MUL[p] % MOD;
		MUL[p << 1 | 1] = MUL[p << 1 | 1] * MUL[p] % MOD;
		MUL[p] = 1;
	}
}
inline long long add(long long a, long long b)
{
	return a + b < MOD ? a + b : a + b - MOD;
}
long long G(int p, int l, int r, int L, int R)
{
	if (L <= l && r <= R)
		return SUM[p];
	int m = l + r >> 1;
	down(p);
	if (R <= m)
		return G(p << 1, l, m, L, R);
	if (L > m)
		return G(p << 1 | 1, m + 1, r, L, R);
	return add(G(p << 1, l, m, L, R), G(p << 1 | 1, m + 1, r, L, R));
}
void P(int x, long long w)
{
	int p = 1, l = 0, r = N;
	while (l < r)
	{
		int m = l + r >> 1;
		down(p);
		if (x <= m)
			p <<= 1, r = m;
		else
			p = p << 1 | 1, l = m + 1;
	}
	SUM[p] = w;
	while (p > 1)
	{
		p >>= 1;
		SUM[p] = add(SUM[p << 1], SUM[p << 1 | 1]);
	}
}
void Pa(int x, long long w)
{
	int p = 1, l = 0, r = N;
	while (l < r)
	{
		int m = l + r >> 1;
		down(p);
		if (x <= m)
			p <<= 1, r = m;
		else
			p = p << 1 | 1, l = m + 1;
	}
	SUM[p] = add(SUM[p], w);
	while (p > 1)
	{
		p >>= 1;
		SUM[p] = add(SUM[p << 1], SUM[p << 1 | 1]);
	}
}
void Mul(int p, int l, int r, int L, int R, long long w)
{
	if (L <= l && r <= R)
	{
		SUM[p] = SUM[p] * w % MOD;
		MUL[p] = MUL[p] * w % MOD;
		return;
	}
	int m = l + r >> 1;
	down(p);
	if (L <= m)
		Mul(p << 1, l, m, L, R, w);
	if (R > m)
		Mul(p << 1 | 1, m + 1, r, L, R, w);
	SUM[p] = add(SUM[p << 1], SUM[p << 1 | 1]);
}
int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		scanf("%d%d", &p[i].x, &p[i].v);
	std::sort(p + 1, p + N + 1, [] (const tok &a, const tok &b) { return a.v < b.v; });
	for (int i = 1; i <= N; i++)
		H[i] = p[i].x;
	std::sort(H + 1, H + N + 1);
	for (int i = 1; i <= N; i++)
		a[i] = std::lower_bound(H + 1, H + N + 1, p[i].x) - H;
	for (int i = N; i; i--)
	{
		Put(a[i], i);
		q[i].r = Max(1, 1, N, 1, a[i]);
	}
	for (int i = 1; i <= N; i++)
		Put(i, N + 1);
	for (int i = 1; i <= N; i++)
	{
		Put(a[i], i);
		q[i].l = Min(1, 1, N, a[i], N) - 1;
	}
	std::sort(q + 1, q + N + 1, [] (const seg &a, const seg &b) { return a.l < b.l || a.l == b.l && a.r < b.r; });
	build(1, 0, N);
	for (int i = 0, j = 1; i < N; i++)
	{
		while (j <= N && q[j].l == i)
		{
			long long W = G(1, 0, N, 0, q[j].r);
			Pa(q[j].r, W);
			if (q[j].r < N)
				Mul(1, 0, N, q[j].r + 1, N, 2);
			j++;
		}
		P(i, 0);
	}
	printf("%lld\n", G(1, 0, N, N, N));
	return 0;
}


Measured memory_bytes: 17152