#include <bits/stdc++.h>

const int N = 200054, mod = 1000000007;

struct linear {
	int k, b, id;
	linear * read() {return scanf("%d%d", &b, &k), this;}
} a[N];

int n;
int L[N], R[N], F[N];

inline void up(int &x, const int y) {x < y ? x = y : 0;}
inline void down(int &x, const int y) {x > y ? x = y : 0;}
inline int & add(int &x, const int y) {return x += y - mod, x += x >> 31 & mod;}
inline int & sub(int &x, const int y) {return x -= y, x += x >> 31 & mod;}

int main() {
	int i, j = 0, ans;
	scanf("%d", &n);
	for (i = 0; i < n; ++i) a[i].read();
	std::sort(a, a + n, [] (const linear &A, const linear &B) {return A.k < B.k;});
	for (i = 0; i < n; ++i) a[i].id = i;
	std::sort(a, a + n, [] (const linear &A, const linear &B) {return A.b < B.b;});
	for (i = n - 1, L[i] = a[i].id; --i >= 0; down(L[i] = L[i + 1], a[i].id));
	for (*R = a->id, i = 1; i < n; ++i) up(R[i] = R[i - 1], a[i].id);
	for (*F = 1, i = 0; i < n; ++i) {
		for (; R[j] < L[i] - 1; ++j);
		add(F[i + 1] = F[i], F[i]);
		if (L[i]) sub(F[i + 1], F[j]);
	}
	for (ans = F[n]; R[j] < n - 1; ++j);
	printf("%d\n", sub(ans, F[j]));
	return 0;
}