#include <bits/stdc++.h>
#define ll long long
#define forr(i, l, r) for (int i = l; i<=r; i++)
#define pii pair <ll, ll>
#define f first
#define s second
using namespace std;
int const N = 3e5 + 100;
pii a[N];
pii dp[N];
pii c[N];
ll n;
ll tong, dem;
int const mod = 1e9 + 7;
pii tree[N];
pii x;
void add(ll& a, ll b)
{
a += b;
if (a >= mod)
a-=mod;
}
void upd(ll i, pii v)
{
for (; i <= dem; i += i & -i) {
if (tree[i].f > v.f)
{
tree[i] = v;
}
else if (tree[i].f == v.f)
{
tree[i].f = v.f;
add(tree[i].s, v.s);
}
}
}
pii query (ll i1)
{
ll ans = 0;
ll res = 1e12;
ll i = i1;
for (; i; i -= i & -i)
res = min(res, tree[i].f);
i = i1;
for (; i; i -= i & -i)
if (res == tree[i].f)
add(ans, tree[i].s);
return {res, ans};
}
ll b[N];
bool ok[N];
int main()
{
// freopen("box.inp", " r", stdin);
// freopen("box.out", "w", stdout);
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cin >>n;
forr(i, 1, n) cin >>a[i].f >> a[i].s;
sort(a + 1, a + 1 + n, [&] (pii x, pii y)
{
if (x.s == y.s)
return x.f > y.f;
return x.s > y.s;
});
forr(i, 1, n) {
b[++dem] = a[i].f;
b[++dem] = a[i].s;
}
forr(i, 0, dem)
tree[i] = {1e12, 0};
// cout << tree[1].f << endl;
sort(b + 1, b + 1 + dem);
forr(i, 1, n) {
c[i].f = lower_bound(b + 1, b + 1 + dem, a[i].f) - b ;
c[i].s = lower_bound(b + 1, b + 1 + dem, a[i].s) - b ;
}
// forr(i, 1, n)
// cout << c[i] << " ";
ll minx = 1e12;
forr(i, 1, n)
{ x = query(dem - c[i].f + 1);
if (x.f == 1e12 && x.s == 0) {
dp[i] = {a[i].s , 1};
minx = min(minx, dp[i].f);
ok[i] = 1;
// upd(c[i].f, dp[i]);
}
else {
dp[i] = {x.f + a[i].s - a[i].f, x.s};
minx = min(minx, x.f + a[i].s - a[i].f);
ok[i] = 0;
// cout << i << " " << x.f + a[i].s - a[i].f << endl;
}
upd(dem - c[i].s + 1, dp[i]);
}
// forr(i, 1, n)
//// if (dp[i].f )
// minx = min(dp[i].f + a[i].f , minx);
// forr(i, 1, n)
// cout << dp[i].f << " " << dp[i].s << endl;
//cout << minx << endl;
forr(i, 1, n)
{
// cout << ok[i] << " " << dp[i].f << " " << i << " " << minx << endl;
if (dp[i].f == minx)
add(tong, dp[i].s);
// if (ok[i])
// {
// if (dp[i].f == minx)
// add(tong, dp[i].s);
// }
// else
// {
// if (dp[i].f + a[i].f == minx)
// add(tong, dp[i].s);
// }
}
cout << tong;
//forr(i, 1, n)
//dp[i] = 1;
//forr(i, 1, n)
//forr(j, i + 1, n)
//if (a[i] <= a[j])
// dp[j] = min(dp[j], dp[i] + 1);
//cout << dp[n];
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgZm9ycihpLCBsLCByKSBmb3IgKGludCBpID0gbDsgaTw9cjsgaSsrKQojZGVmaW5lIHBpaSBwYWlyIDxsbCwgbGw+CiNkZWZpbmUgZiBmaXJzdAojZGVmaW5lIHMgc2Vjb25kCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKaW50IGNvbnN0IE4gPSAzZTUgKyAxMDA7CnBpaSBhW05dOwpwaWkgZHBbTl07CnBpaSBjW05dOwpsbCBuOwpsbCB0b25nLCBkZW07CmludCBjb25zdCBtb2QgPSAxZTkgKyA3OwpwaWkgdHJlZVtOXTsKcGlpIHg7CnZvaWQgYWRkKGxsJiBhLCBsbCBiKQp7CiAgICBhICs9IGI7CiAgICBpZiAoYSA+PSBtb2QpCiAgICAgICAgYS09bW9kOwp9CnZvaWQgdXBkKGxsIGksIHBpaSB2KQp7CiAgICAgZm9yICg7IGkgPD0gZGVtOyBpICs9IGkgJiAtaSkgewppZiAodHJlZVtpXS5mID4gdi5mKQp7CiAgIHRyZWVbaV0gPSB2Owp9CmVsc2UgaWYgKHRyZW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