#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define enable_ll
#ifdef enable_ll
    #define int long long
#endif
#ifdef DEBUG
    #define out(x) cout<<x<<" "
    #define outln(x) cout<<x<<endl
    #define see(x) cout<<#x<<"="<<x<<" "
    #define seeln(x) cout<<#x<<"="<<x<<endl
    #define line cout<<"---------------------\n"
#else
    #define out(x)
    #define outln(x)
    #define see(x)
    #define seeln(x)
    #define line
#endif
#define m_p make_pair
#define pii pair<int,int>
#define piii pair<int,pii>
template <class T> void read(T &x)
{
    x=0; char c=getchar(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=getchar();
    while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if (flag) x=-x;
}
template <class T> void write(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) write(x/10);
    putchar(x%10+48);
}
template <class T> void write_blank(T x)
{
    write(x);
    putchar(' ');
}
template <class T> void writeln(T x)
{
    write(x);
    putchar('\n');
}

template <class T> T Min(const T &a,const T &b){return (a<b ? a : b);}
template <class T> T Max(const T &a,const T &b){return (a>b ? a : b);}
template <class T> bool checkmin(T &a,T b){return b<a ? a=b,1 : 0;}
template <class T> bool checkmax(T &a,T b){return b>a ? a=b,1 : 0;}
const int N=200029;
const int inf=(1LL<<50);
const int mod=1000000000+7;
int n,f[N],g[N],mx=0;
void add(int &a,int b)
{
    a+=b;
    a%=mod;
}

struct node
{
    int out,in;
    bool operator < (const node &rhs) const
    {
        if (in==rhs.in) return out<rhs.out;
        return in<rhs.in;
    }
}a[N];

void init()
{
    read(n);
    for (int i=1;i<=n;++i)
    {
        read(a[i].out);
        read(a[i].in);
        checkmax(mx,a[i].in);
    }
    sort(a+1,a+n+1);
    #ifdef DEBUG
    line;
    for (int i=1;i<=n;++i)
    {
        out(a[i].out),outln(a[i].in);
    }
    #endif
}

void solve()
{
    int ans=0,tmp=0,mi=inf,total=0;
    #ifdef DEBUG
    line;
    #endif
    for (int i=1;i<=n;++i)
    {
        f[i]=a[i].in,g[i]=1;
        //see(i); see(f[i]); seeln(g[i]);
        while (tmp<n&&a[tmp+1].out<=a[i].in)
        {
            ++tmp;
            if (f[tmp]-a[tmp].out<mi)
            {
                mi=f[tmp]-a[tmp].out;
                total=g[tmp];
            }
            else if (f[tmp]-a[tmp].out==mi)
            {
                add(total,g[tmp]);
            }
        }
        if (mi+a[i].in<f[i])
        {
            f[i]=mi+a[i].in;
            g[i]=total;
        }
        else if (mi+a[i].in==f[i])
        {
            add(g[i],total);
        }
        #ifdef DEBUG
        cout<<"f g:  "<<f[i]<<" "<<g[i]<<endl;
        #endif
    }
    mi=inf;
    for (int i=1;i<=n;++i)
    {
        if (f[i]<mi&&a[i].out>mx)
        {
            mi=f[i];
        }
    }
    #ifdef DEBUG
    cout<<mi<<endl;
    #endif
    for (int i=1;i<=n;++i)
    {
        if (f[i]==mi&&a[i].out>mx)
        {
            add(ans,g[i]);
        }
    }
    printf("%lld\n",ans);
}

#undef int
int main()
{
    init();
    solve();
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;

int t, n, mn[200001], mod = 1e9 + 7, sgtr[600001], ans[200001];
pii a[200001];
map<int, int> mep;

int query(int node, int l, int r, int L, int R)
{
	if ( l > R || r < L )
		return INT_MAX;

	if ( l >= L && r <= R )
		return sgtr[node];

	int mid = (l + r) / 2;

	return min(query(node * 2, l, mid, L, R), query(node * 2 + 1, mid + 1, r, L, R));
}

void upd(int node, int l, int r, int idx, int num)
{
	if ( l > idx || r < idx )
		return;

	if ( l == r )
	{
		sgtr[node] = num;
		return;
	}

	int mid = (l + r) / 2;

	upd(node * 2, l, mid, idx, num);
	upd(node * 2 + 1, mid + 1, r, idx, num);

	sgtr[node] = min(sgtr[node * 2], sgtr[node * 2 + 1]);
}

int main ()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> a[i].ff >> a[i].ss;

	sort(a + 1, a + n + 1);

	for (int i = 1; i <= n; i++)
	{
		int l = 0, r = i - 1;

		while (l + 1 < r)
		{
			int mid = (l + r) / 2;

			if ( a[mid].ff <= a[i].ss )
				l = mid;

			else
				r = mid;
		}

		if ( a[r].ff <= a[i].ss && l < r )
			l++;

		mn[i] = query(1, 0, n, 0, l) + a[i].ss;
		upd(1, 0, n, i, mn[i] - a[i].ff);
		ans[i] = mep[mn[i] - a[i].ss] + 1;
		mep[mn[i] - a[i].ff] = (mep[mn[i] - a[i].ff] + ans[i]) % mod;
	}

	cout << ans[n];
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;

int t, n, mn[200001], mod = 1e9 + 7, sgtr[600001], ans[200001], mx, mni = 1e9, cr, rcmp[200001];
pii a[200001], comp[200001];
map<int, int> mep[400001], sna, cmp;
vector <int> vc;

void up(int x, int y, int z)
{
	while ( x <= cr )
	{
		mep[x][y] = (mep[x][y] + z) % mod;
		x += (x & (-x));
	}
}

int ol(int x, int y)
{
	int s = 0;

	while ( x > 0 )
	{
		s = (s + mep[x][y]) % mod;
		x -= (x & -x);
	}

	return s;
}

int query(int node, int l, int r, int L, int R)
{
	if ( l > R || r < L )
		return INT_MAX;

	if ( l >= L && r <= R )
		return sgtr[node];

	int mid = (l + r) / 2;

	return min(query(node * 2, l, mid, L, R), query(node * 2 + 1, mid + 1, r, L, R));
}

void upd(int node, int l, int r, int idx, int num)
{
	if ( l > idx || r < idx )
		return;

	if ( l == r )
	{
		sgtr[node] = num;
		return;
	}

	int mid = (l + r) / 2;

	upd(node * 2, l, mid, idx, num);
	upd(node * 2 + 1, mid + 1, r, idx, num);

	sgtr[node] = min(sgtr[node * 2], sgtr[node * 2 + 1]);
}

int main ()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].ff >> a[i].ss;
		mx = max(mx, a[i].ss);
		vc.pub(a[i].ff);
		vc.pub(a[i].ss);
	}

	sort(vc.begin(), vc.end());

	for (int i = 0; i < vc.size(); i++)
		if ( !cmp[vc[i]] )
			cmp[vc[i]] = ++cr, rcmp[cr] = vc[i];

	for (int i = 1; i <= n; i++)
	{
		a[i].ff = cmp[a[i].ff];
		a[i].ss = cmp[a[i].ss];
	}

	sort(a + 1, a + n + 1);
	up(1, 0, 1);

	for (int i = 1; i <= n; i++)
	{
		int l = 0, r = i - 1;

		while (l + 1 < r)
		{
			int mid = (l + r) / 2;

			if ( rcmp[a[mid].ff] <= rcmp[a[i].ss] )
				l = mid;

			else
				r = mid;
		}

		if ( rcmp[a[r].ff] <= rcmp[a[i].ss] && l < r )
			l++;

		mn[i] = query(1, 0, n, 0, l) + rcmp[a[i].ss];
		upd(1, 0, n, i, mn[i] - rcmp[a[i].ff]);
		ans[i] = ol(a[i].ss, mn[i] - rcmp[a[i].ss]);

		if ( rcmp[a[i].ff] > mx )
		{
			sna[mn[i]] = (sna[mn[i]] + ans[i]) % mod;
			mni = min(mni, mn[i]);
		}

		up(a[i].ff, mn[i] - rcmp[a[i].ff], ans[i]);
	}

	cout << sna[mni] << "\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;

int t, n, mn[200001], mod = 1e9 + 7, sgtr[600001], ans[200001], mx, mni = 1e9, cr, rcmp[400001];
pii a[200001], comp[200001];
map<int, int> mep[400001], sna, cmp;
vector <int> vc;

void up(int x, int y, int z)
{
	while ( x <= cr )
	{
		mep[x][y] = (mep[x][y] + z) % mod;
		x += (x & (-x));
	}
}

int ol(int x, int y)
{
	int s = 0;

	while ( x > 0 )
	{
		s = (s + mep[x][y]) % mod;
		x -= (x & -x);
	}

	return s;
}

int query(int node, int l, int r, int L, int R)
{
	if ( l > R || r < L )
		return INT_MAX;

	if ( l >= L && r <= R )
		return sgtr[node];

	int mid = (l + r) / 2;

	return min(query(node * 2, l, mid, L, R), query(node * 2 + 1, mid + 1, r, L, R));
}

void upd(int node, int l, int r, int idx, int num)
{
	if ( l > idx || r < idx )
		return;

	if ( l == r )
	{
		sgtr[node] = num;
		return;
	}

	int mid = (l + r) / 2;

	upd(node * 2, l, mid, idx, num);
	upd(node * 2 + 1, mid + 1, r, idx, num);

	sgtr[node] = min(sgtr[node * 2], sgtr[node * 2 + 1]);
}

int main ()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].ff >> a[i].ss;
		mx = max(mx, a[i].ss);
		vc.pub(a[i].ff);
		vc.pub(a[i].ss);
	}

	sort(vc.begin(), vc.end());

	for (int i = 0; i < vc.size(); i++)
		if ( !cmp[vc[i]] )
			cmp[vc[i]] = ++cr, rcmp[cr] = vc[i];

	for (int i = 1; i <= n; i++)
	{
		a[i].ff = cmp[a[i].ff];
		a[i].ss = cmp[a[i].ss];
	}

	sort(a + 1, a + n + 1);
	up(1, 0, 1);

	for (int i = 1; i <= n; i++)
	{
		int l = 0, r = i - 1;

		while (l + 1 < r)
		{
			int mid = (l + r) / 2;

			if ( rcmp[a[mid].ff] <= rcmp[a[i].ss] )
				l = mid;

			else
				r = mid;
		}

		if ( rcmp[a[r].ff] <= rcmp[a[i].ss] && l < r )
			l++;

		mn[i] = query(1, 0, n, 0, l) + rcmp[a[i].ss];
		upd(1, 0, n, i, mn[i] - rcmp[a[i].ff]);
		ans[i] = ol(a[i].ss, mn[i] - rcmp[a[i].ss]);

		if ( rcmp[a[i].ff] > mx )
		{
			sna[mn[i]] = (sna[mn[i]] + ans[i]) % mod;
			mni = min(mni, mn[i]);
		}

		up(a[i].ff, mn[i] - rcmp[a[i].ff], ans[i]);
	}

	cout << sna[mni] << "\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;

int t, n, mn[200001], mod = 1e9 + 7, sgtr[600001], ans[200001], mx, mni = 1e9, baa = 1e9, cr, rcmp[200001];
pii a[200001], comp[200001];
map<int, int> mep[200001], sna, cmp;
vector <int> vc;

void up(int x, int y, int z)
{
	while ( x <= cr )
	{
		mep[x][y] = (mep[x][y] + z);
		x += (x & (-x));
	}
}

int ol(int x, int y)
{
	int s = 0;

	while ( x > 0 )
	{
		s = (s + mep[x][y]) % mod;
		x -= (x & -x);
	}

	s = (s + mep[0][y]) % mod;

	return s;
}

int query(int node, int l, int r, int L, int R)
{
	if ( l > R || r < L )
		return INT_MAX;

	if ( l >= L && r <= R )
		return sgtr[node];

	int mid = (l + r) / 2;

	return min(query(node * 2, l, mid, L, R), query(node * 2 + 1, mid + 1, r, L, R));
}

void upd(int node, int l, int r, int idx, int num)
{
	if ( l > idx || r < idx )
		return;

	if ( l == r )
	{
		sgtr[node] = num;
		return;
	}

	int mid = (l + r) / 2;

	upd(node * 2, l, mid, idx, num);
	upd(node * 2 + 1, mid + 1, r, idx, num);

	sgtr[node] = min(sgtr[node * 2], sgtr[node * 2 + 1]);
}

int main ()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].ff >> a[i].ss;
		mx = max(mx, a[i].ss);
		vc.pub(a[i].ff);
		vc.pub(a[i].ss);
	}

	sort(vc.begin(), vc.end());

	for (int i = 0; i < vc.size(); i++)
		if ( !cmp[vc[i]] )
			cmp[vc[i]] = ++cr, rcmp[cr] = vc[i];

	for (int i = 1; i <= n; i++)
	{
		a[i].ff = cmp[a[i].ff];
		a[i].ss = cmp[a[i].ss];
	}

	sort(a + 1, a + n + 1);
	up(1, 0, 1);

	for (int i = 1; i <= n; i++)
	{
		int l = 0, r = i - 1;

		while (l + 1 < r)
		{
			int mid = (l + r) / 2;

			if ( rcmp[a[mid].ff] <= rcmp[a[i].ss] )
				l = mid;

			else
				r = mid;
		}

		if ( rcmp[a[r].ff] <= rcmp[a[i].ss] && l < r )
			l++;

		mn[i] = query(1, 0, n, 0, l) + rcmp[a[i].ss];
		upd(1, 0, n, i, mn[i] - rcmp[a[i].ff]);
		ans[i] = ol(a[i].ss, mn[i] - rcmp[a[i].ss]);

		if ( rcmp[a[i].ff] > mx )
		{
			sna[mn[i]] = (sna[mn[i]] + ans[i]) % mod;
			mni = min(mni, mn[i]);
		}

		up(a[i].ff, mn[i] - rcmp[a[i].ff], ans[i]);
	}

	cout << sna[mni] << "\n";

//	for (int i = 1; i <= n; i++)
//	{
//		cout << mn[i] << " " << ans[i] << "\n";
//	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;

int t, n, mn[200001], mod = 1e9 + 7, sgtr[600001], ans[200001], mx, mni = 1e9, cr, rcmp[200001];
pii a[200001], comp[200001];
map<int, int> mep[200001], sna, cmp;
vector <int> vc;

void up(int x, int y, int z)
{
	while ( x <= cr )
	{
		mep[x][y] = (mep[x][y] + z) % mod;
		x += (x & (-x));
	}
}

int ol(int x, int y)
{
	int s = 0;

	while ( x > 0 )
	{
		s = (s + mep[x][y]) % mod;
		x -= (x & -x);
	}

	return s;
}

int query(int node, int l, int r, int L, int R)
{
	if ( l > R || r < L )
		return INT_MAX;

	if ( l >= L && r <= R )
		return sgtr[node];

	int mid = (l + r) / 2;

	return min(query(node * 2, l, mid, L, R), query(node * 2 + 1, mid + 1, r, L, R));
}

void upd(int node, int l, int r, int idx, int num)
{
	if ( l > idx || r < idx )
		return;

	if ( l == r )
	{
		sgtr[node] = num;
		return;
	}

	int mid = (l + r) / 2;

	upd(node * 2, l, mid, idx, num);
	upd(node * 2 + 1, mid + 1, r, idx, num);

	sgtr[node] = min(sgtr[node * 2], sgtr[node * 2 + 1]);
}

int main ()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].ff >> a[i].ss;
		mx = max(mx, a[i].ss);
		vc.pub(a[i].ff);
		vc.pub(a[i].ss);
	}

	sort(vc.begin(), vc.end());

	for (int i = 0; i < vc.size(); i++)
		if ( !cmp[vc[i]] )
			cmp[vc[i]] = ++cr, rcmp[cr] = vc[i];

	for (int i = 1; i <= n; i++)
	{
		a[i].ff = cmp[a[i].ff];
		a[i].ss = cmp[a[i].ss];
	}

	sort(a + 1, a + n + 1);
	up(1, 0, 1);

	for (int i = 1; i <= n; i++)
	{
		int l = 0, r = i - 1;

		while (l + 1 < r)
		{
			int mid = (l + r) / 2;

			if ( rcmp[a[mid].ff] <= rcmp[a[i].ss] )
				l = mid;

			else
				r = mid;
		}

		if ( rcmp[a[r].ff] <= rcmp[a[i].ss] && l < r )
			l++;

		mn[i] = query(1, 0, n, 0, l) + rcmp[a[i].ss];
		upd(1, 0, n, i, mn[i] - rcmp[a[i].ff]);
		ans[i] = ol(a[i].ss, mn[i] - rcmp[a[i].ss]);

		if ( rcmp[a[i].ff] > mx )
		{
			sna[mn[i]] = (sna[mn[i]] + ans[i]) % mod;
			mni = min(mni, mn[i]);
		}

		up(a[i].ff, mn[i] - rcmp[a[i].ff], ans[i]);
	}

	cout << sna[mni] << "\n";
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'

const ll N=400005;
vector<pair<pll,ll>> all;
ll dp[N],mn[N],kitne[N];
map<ll,ll> cnt;
pll p[N];

int main()
{
    fastio;
    #ifdef APNA_IO
        start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif

    ll n;cin>>n;

    for(ll i=1;i<=n;i++)
    {
        cin>>p[i].ss>>p[i].ff;
        all.pb({{p[i].ff,1},i});
        all.pb({{p[i].ss,0},i});
    }
    all.pb({{0,0},0});
    sort(all.begin(), all.end());

    kitne[0]=1;
    // mn[0]=inf;
    for(ll i=0;i<all.size();i++)
    {
        if(!all[i].ff.ss)
        {
            cnt[mn[i]]=(cnt[mn[i]]+kitne[i])%mod;
            if(i>0)
                mn[i]=min(mn[i],mn[i-1]);
        }
        else
        {
            mn[i]=mn[i-1];
            ll y=mn[i];
            // if(mn[i]==inf) y=0;

            ll x=y+all[i].ff.ff;

            ll a=all[i].ss;
            ll b=p[a].ss;
            const pair<pll,ll> xx={{b,0},a};
            ll c=lb(all.begin(), all.end(),xx)-all.begin();

            dp[c]=x;
            mn[c]=x-all[c].ff.ff;
            kitne[c]=cnt[mn[i]];
        }
    }

    // for(ll i=0;i<all.size();i++)
    //     cout<<mn[i]<<" ";
    // cout<<endl;
    // for(ll i=0;i<all.size();i++)
    //     cout<<dp[i]<<" ";
    // cout<<endl;
    // for(ll i=0;i<all.size();i++)
    //     cout<<kitne[i]<<" ";
    // cout<<endl;

    ll ans=0,sm=inf;
    for(ll i=all.size()-1;i>=0;i--)
        if(all[i].ff.ss)
            break;
        else
            sm=min(sm,dp[i]);

    for(ll i=all.size()-1;i>=0;i--)
        if(all[i].ff.ss)
            break;
        else if(dp[i]==sm)
            ans=(ans+kitne[i])%mod;

    cout<<ans;

    #ifdef APNA_IO
        end_routine();
    #endif
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'

const ll N=400005;
vector<pair<pll,ll>> all;
ll dp[N],mn[N],kitne[N];
map<ll,ll> cnt;
pll p[N];

int main()
{
    fastio;
    #ifdef APNA_IO
        start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif

    ll n;cin>>n;

    for(ll i=1;i<=n;i++)
    {
        cin>>p[i].ss>>p[i].ff;
        all.pb({{p[i].ff,1},i});
        all.pb({{p[i].ss,0},i});
    }
    all.pb({{0,0},0});
    sort(all.begin(), all.end());

    kitne[0]=1;
    // mn[0]=inf;
    for(ll i=0;i<all.size();i++)
    {
        if(!all[i].ff.ss)
        {
            cnt[mn[i]]=(cnt[mn[i]]+kitne[i])%mod;
            if(i>0)
                mn[i]=min(mn[i],mn[i-1]);
        }
        else
        {
            mn[i]=mn[i-1];
            ll y=mn[i];
            // if(mn[i]==inf) y=0;

            ll x=y+all[i].ff.ff;

            ll a=all[i].ss;
            ll b=p[a].ss;
            const pair<pll,ll> xx={{b,0},a};
            ll c=lb(all.begin(), all.end(),xx)-all.begin();

            dp[c]=x;
            mn[c]=x-all[c].ff.ff;
            kitne[c]=cnt[mn[i]];
        }
    }

    // for(ll i=0;i<all.size();i++)
    //     cout<<mn[i]<<" ";
    // cout<<endl;
    // for(ll i=0;i<all.size();i++)
    //     cout<<dp[i]<<" ";
    // cout<<endl;
    // for(ll i=0;i<all.size();i++)
    //     cout<<kitne[i]<<" ";
    // cout<<endl;

    ll ans=0,sm=inf;
    for(ll i=all.size()-1;i>=0;i--)
        if(all[i].ff.ss)
            break;
        else
            sm=min(sm,dp[i]);

    for(ll i=all.size()-1;i>=0;i--)
        if(all[i].ff.ss)
            break;
        else if(dp[i]==sm)
            ans+=kitne[i];

    cout<<ans;

    #ifdef APNA_IO
        end_routine();
    #endif
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'

const ll N=400005;
vector<pair<pll,ll>> all;
ll dp[N],mn[N],kitne[N];
map<ll,ll> cnt;
pll p[N];

int main()
{
    fastio;
    #ifdef APNA_IO
        start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif

    ll n;cin>>n;

    for(ll i=1;i<=n;i++)
    {
        cin>>p[i].ss>>p[i].ff;
        all.pb({{p[i].ff,1},i});
        all.pb({{p[i].ss,0},i});
    }
    all.pb({{0,0},0});
    sort(all.begin(), all.end());

    kitne[0]=1;
    for(ll i=0;i<all.size();i++)
    {
        if(!all[i].ff.ss)
        {
            cnt[mn[i]]=(cnt[mn[i]]+kitne[i])%mod;
            if(i>0)
                mn[i]=min(mn[i],mn[i-1]);
        }
        else
        {
            mn[i]=mn[i-1];
            ll x=mn[i]+all[i].ff.ff;

            ll a=all[i].ss;
            ll b=p[a].ss;
            const pair<pll,ll> xx={{b,0},a};
            ll c=lb(all.begin(), all.end(),xx)-all.begin();

            dp[c]=x;
            mn[c]=x-all[c].ff.ff;
            kitne[c]=cnt[mn[i]];
        }
    }

    // for(ll i=0;i<all.size();i++)
    //     cout<<mn[i]<<" ";
    // cout<<endl;
    // for(ll i=0;i<all.size();i++)
    //     cout<<dp[i]<<" ";
    // cout<<endl;
    // for(ll i=0;i<all.size();i++)
    //     cout<<kitne[i]<<" ";
    // cout<<endl;

    ll ans=0;
    for(ll i=all.size()-1;i>=0;i--)
        if(all[i].ff.ss)
            break;
        else
            ans+=kitne[i];

    cout<<ans;

    #ifdef APNA_IO
        end_routine();
    #endif
}


#include<bits/stdc++.h>
#define maxl 400010

using namespace std;
const int mod=1e9+7;
const long long inf=1ll<<62;

int n,m,x,cnt,tot,mir,mxl;
long long ans;
struct node
{
	int l,r;
}a[maxl];
long long f[maxl];
long long q[maxl],id[maxl],sum[maxl],idr[maxl];
int num[maxl*2];
bool in[maxl];
char s[maxl];

inline bool cmp(const node &x,const node &y)
{
	if(x.l==y.l)
		return x.r<y.r;
	else
		return x.l<y.l;
}

inline void prework()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].r,&a[i].l),num[++cnt]=a[i].l,num[++cnt]=a[i].r;
	sort(num+1,num+1+cnt);
	tot=unique(num+1,num+1+cnt)-num-1;
	mir=tot+1;mxl=0;
	for(int i=1;i<=n;i++)
	{
		a[i].l=lower_bound(num+1,num+1+tot,a[i].l)-num;
		a[i].r=lower_bound(num+1,num+1+tot,a[i].r)-num;
		mxl=max(a[i].l,mxl);
		mir=min(a[i].r,mir);
	}
	sort(a+1,a+1+n,cmp);
}

inline void mainwork()
{
	for(int i=1;i<=tot;i++)
		sum[i]=0,f[i]=inf;
	long long tmp;
	int head=0,tail=1;
	head=1;
	sum[0]=1;f[0]=0;
	q[1]=0;id[1]=0;idr[1]=inf;
	for(int i=1;i<=n;i++)
	{
		while(head<=tail && idr[head]<=a[i].l)
			head++;
		if(a[i].l>a[i-1].l)
		{
			for(int j=a[i-1].l+1;j<=a[i].l;j++)
			if(f[j]<inf)
			{
				while(f[j]-j<q[tail] && head<=tail)
					tail--;
				q[++tail]=f[j]-j;
				id[tail]=j;idr[tail]=inf;
			}
		}
		tmp=q[head]+a[i].l;
		idr[head]=min(1ll*a[i].r,idr[head]);
		if(tmp<f[a[i].r])
		{
			f[a[i].r]=tmp;
			sum[a[i].r]=sum[id[head]];
		}
		else if(tmp==f[a[i].r])
			sum[a[i].r]=(sum[a[i].r]+sum[id[head]])%mod;
	}
	long long mini=inf;
	for(int i=n;i>=1;i--)
	{
		if(a[i].r>mxl)
			mini=min(f[a[i].r],mini);
	}
	for(int i=n;i>=1;i--)
	if(a[i].r>mxl && f[a[i].r]==mini)
	{
		if(!in[a[i].r])
			ans=(ans+sum[a[i].r])%mod;
		in[a[i].r]=true;
	}
}

inline void print()
{
	ans=ans%mod;
	printf("%lld",ans);
}

int main()
{

	prework();
	mainwork();
	print();

	return 0;
}


#include<bits/stdc++.h>
#define maxl 300010

using namespace std;
const int mod=1e9+7;
const long long inf=1ll<<62;

int n,m,x,cnt,tot,mir,mxl;
long long ans;
struct node
{
	int l,r;
}a[maxl];
long long h[maxl],c[maxl],c[maxl],f[maxl];
int num[maxl*2];
char s[maxl];

inline bool cmp(const node &x,const node &y)
{
	if(x.l==y.l)
		return x.r<y.r;
	else
		return x.l<y.l;
}

inline void prework()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].r,&a[i].l),num[++cnt]=a[i].l,num[++cnt]=a[i].r;
	tot=unique(num+1,num+1+cnt)-num-1;
	mir=tot+1;mxl=0;
	for(int i=1;i<=n;i++)
	{
		a[i].l=lower_bound(num+1,num+1+tot,a[i].l)-num;
		a[i].r=lower_bound(num+1,num+1+tot,a[i].r)-num;
		mxl=max(a[i].l,mxl);
		mir=min(a[i].r,mir);
	}
	sort(a+1,a+1+n,cmp);
}

inline void upd(int i)
{
	while(i<=tot && i)
	{
		h[i]=c[i];
		for(int k=1;k<(i&-i);k<<=1)
			h[i]=max(h[i],h[i-k]);
		i+=i&-i;
	}
}

inline long long qry(int l,int r)
{
	int len=r-l+1;
	long long ret=inf;
	while(len && r)
	{
		if(len<(r&-r))
		{
			ret=min(ret,c[r]);
			r--;len--;
		}else
		{
			ret=min(ret,h[r]);
			len-=(r&-r);
			r-=r&-r;
		}
	}
	return ret;
}

inline void mainwork()
{
	long long tmp;
	for(int i=1;i<=tot;i++)
		c[i]=inf;
	for(int i=1;i<=n;i++)
	{
		if(a[i].l<mir)
			tmp=num[a[i].l];
		else
			tmp=qry(1,a[i].l)+num[a[i].l];
		f[i]=tmp;
		if(tmp-num[a[i].r]<c[a[i].r])
		{
			c[a[i].r]=tmp-num[a[i].r];
			c[a[i].r]=1;
			upd(a[i].r);
		}
	}
	ans=inf;
	for(int i=n;i>=1;i--)
	{
		if(a[i].r>mxl)
			ans=min(f[i],ans);
	}
}

inline void print()
{
	ans=ans%mod;
	printf("%lld",ans);
}

int main()
{

	prework();
	mainwork();
	print();

	return 0;
}


#include<bits/stdc++.h>
#define maxl 400010

using namespace std;
const int mod=1e9+7;
const long long inf=1ll<<62;

int n,m,x,cnt,tot,mir,mxl;
long long ans;
struct node
{
	int l,r;
}a[maxl];
long long f[maxl],q[maxl],sum[maxl];
int num[maxl*2];
bool in[maxl];
char s[maxl];

inline bool cmp(const node &x,const node &y)
{
	if(x.l==y.l)
		return x.r<y.r;
	else
		return x.l<y.l;
}

inline void prework()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].r,&a[i].l),num[++cnt]=a[i].l,num[++cnt]=a[i].r;
	sort(num+1,num+1+cnt);
	tot=unique(num+1,num+1+cnt)-num-1;
	mir=tot+1;mxl=0;
	for(int i=1;i<=n;i++)
	{
		a[i].l=lower_bound(num+1,num+1+tot,a[i].l)-num;
		a[i].r=lower_bound(num+1,num+1+tot,a[i].r)-num;
		mxl=max(a[i].l,mxl);
		mir=min(a[i].r,mir);
	}
	sort(a+1,a+1+n,cmp);
}

inline void mainwork()
{
	for(int i=1;i<=tot;i++)
		sum[i]=0,f[i]=inf,q[i]=inf;
	long long tmp;
	sum[0]=1;f[0]=inf;q[0]=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i].l>a[i-1].l)
		{
			for(int j=a[i-1].l+1;j<=a[i].l;j++)
			{
				if(q[j]==q[j-1])
					sum[j]=(sum[j-1]+sum[j])%mod;
				else if(q[j]>q[j-1])
				{
					q[j]=q[j-1];
					sum[j]=sum[j-1];
				}
			}
		}
		f[a[i].r]=q[a[i].l]+num[a[i].l];
		tmp=f[a[i].r]-num[a[i].r];
		if(tmp<q[a[i].r])
		{
			q[a[i].r]=tmp;
			sum[a[i].r]=sum[a[i].l];
		}
		else if(tmp==q[a[i].r])
			sum[a[i].r]=(sum[a[i].r]+sum[a[i].l])%mod;
	}
	long long mini=inf;
	for(int i=n;i>=1;i--)
	{
		if(a[i].r>mxl)
			mini=min(f[a[i].r],mini);
	}
	for(int i=n;i>=1;i--)
	if(a[i].r>mxl)
	{
		if(!in[a[i].r])
			ans=(ans+sum[a[i].r])%mod;
		in[a[i].r]=true;
	}
}

inline void print()
{
	ans=ans%mod;
	printf("%lld",ans);
}

int main()
{

	prework();
	mainwork();
	print();

	return 0;
}


#include<bits/stdc++.h>
#define maxl 400010

using namespace std;
const int mod=1e9+7;
const long long inf=1ll<<62;

int n,m,x,cnt,tot,mir,mxl;
long long ans;
struct node
{
	int l,r;
}a[maxl];
long long f[maxl],q[maxl],sum[maxl];
int num[maxl*2];
bool in[maxl];
char s[maxl];

inline bool cmp(const node &x,const node &y)
{
	if(x.l==y.l)
		return x.r<y.r;
	else
		return x.l<y.l;
}

inline void prework()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].r,&a[i].l),num[++cnt]=a[i].l,num[++cnt]=a[i].r;
	sort(num+1,num+1+cnt);
	tot=unique(num+1,num+1+cnt)-num-1;
	mir=tot+1;mxl=0;
	for(int i=1;i<=n;i++)
	{
		a[i].l=lower_bound(num+1,num+1+tot,a[i].l)-num;
		a[i].r=lower_bound(num+1,num+1+tot,a[i].r)-num;
		mxl=max(a[i].l,mxl);
		mir=min(a[i].r,mir);
	}
	sort(a+1,a+1+n,cmp);
}

inline void mainwork()
{
	for(int i=1;i<=tot;i++)
		sum[i]=0,f[i]=inf,q[i]=inf;
	long long tmp;
	sum[0]=1;f[0]=inf;q[0]=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i].l>a[i-1].l)
		{
			for(int j=a[i-1].l+1;j<=a[i].l;j++)
			{
				if(q[j]==q[j-1])
					sum[j]=(sum[j-1]+sum[j])%mod;
				else if(q[j]>q[j-1])
				{
					q[j]=q[j-1];
					sum[j]=sum[j-1];
				}
			}
		}
		f[a[i].r]=q[a[i].l]+num[a[i].l];
		tmp=f[a[i].r]-num[a[i].r];
		if(tmp<q[a[i].r])
		{
			q[a[i].r]=tmp;
			sum[a[i].r]=sum[a[i].l];
		}
		else if(tmp==q[a[i].r])
			sum[a[i].r]=(sum[a[i].r]+sum[a[i].l])%mod;
	}
	long long mini=inf;
	for(int i=n;i>=1;i--)
	{
		if(a[i].r>mxl)
			mini=min(f[a[i].r],mini);
	}
	for(int i=n;i>=1;i--)
	if(a[i].r>mxl)
	{
		if(!in[a[i].r] && f[a[i].r]==mini)
			ans=(ans+sum[a[i].r])%mod;
		in[a[i].r]=true;
	}
}

inline void print()
{
	ans=ans%mod;
	printf("%lld",ans);
}

int main()
{

	prework();
	mainwork();
	print();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define INF 1000000000000000000

unordered_map<int, ll> memo;
map<int, ll> dp, sum_table;
unordered_map<int, pair<int, bool> > pt_data;

ll power(ll m, ll n)
{
    if (n == 0)
        return 1;
    if(n == 1)
        return m%mod;
    else if(n%2)
    {
        ll res = ((power(m,(n/2)))%mod);
        return (((m*res)%mod)*res)%mod;
    }
    else
    {
        ll res = ((power(m,(n/2)))%mod);
        return (res*res)%mod;
    }
}

int bin_search(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j){

    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first >= num.second){

        int idx = bin_search(num, vec, i, mid-1);

        if(idx != -1)
            return idx;

        return mid;
    }

    else{
        return bin_search(num, vec, mid+1, j);
    }
}

// int bin_search_min(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j, ll weight){

//     if((j-i) < 0){
//         return -1;
//     }

//     int mid = i + ((j-i)/2);

//     if(vec[mid].first >= num.second){

//         if(weight > ((vec[mid].first) - (num.second - num.first)))
//             return bin_search_min(num, vec, i, mid-1, weight);

//         else{

//             int idx = bin_search_min(num, vec, i, mid-1, weight);

//             if(idx != -1)
//                 return idx;

//             return mid;
//         }
//     }

//     else{
//         return bin_search_min(num, vec, mid+1, j, weight);
//     }
// }

int sum_table_compute(vector<pair<ll, ll> > vec, int parent_idx, int idx ,ll weight){

    if((memo[idx] - (vec[parent_idx].second - vec[parent_idx].first)) > weight){
        int counter = bin_search(vec[parent_idx], vec, idx+1, (vec.size() - 1));

        if(counter != -1)
            return sum_table_compute(vec, parent_idx, counter, weight);
        else
            return -1;
    }

    else{

        if(sum_table.find(idx) != sum_table.end()){
            return idx;
        }

        int counter = bin_search(vec[parent_idx], vec, idx+1, (vec.size() - 1));

        sum_table[idx] = 0;

        if(vec[idx].first == vec[idx].second){
            if(counter != -1){

                int counter_idx = sum_table_compute(vec, parent_idx, counter, weight);
                if(counter_idx != -1){
                    if(pt_data[counter_idx].second){
                        pt_data[idx].first = 1;
                        pt_data[idx].second = true;
                        sum_table[idx] = (sum_table[idx] + 2*sum_table[counter_idx])%mod;
                    }
                    else{
                        pt_data[idx].first = 1;
                        pt_data[idx].second = false;
                        sum_table[idx] = sum_table[counter_idx]%mod;
                    }
                }

                else{
                    sum_table[idx] = 1;
                    pt_data[idx].first = 1;
                    pt_data[idx].second = false;
                }
            }

            else{
                sum_table[idx] = 1;
                pt_data[idx].first = 1;
                pt_data[idx].second = false;
            }
        }
        else{

            pt_data[idx].first = 1;
            pt_data[idx].second = true;

            int idx_child = bin_search(vec[idx], vec, idx+1, (vec.size() - 1));

            if(idx_child == -1){
                sum_table[idx] = 1;
            }

            else{
                int idx_child_child = sum_table_compute(vec, idx, idx_child, weight + (vec[idx].second - vec[idx].first));

                if(idx_child_child != -1){
                    sum_table[idx] = (sum_table[idx] + sum_table[idx_child_child])%mod;
                }
                else{
                    sum_table[idx] = 1;
                }
            }

            if(counter != -1){
                int counter_idx = sum_table_compute(vec, parent_idx, counter, weight);
                if(counter_idx != -1){
                    sum_table[idx] = (sum_table[idx] + sum_table[counter_idx])%mod;
                }
            }
        }

        return idx;
    }

}

// void solve(vector<pair<ll, ll> > vec, int idx, ll weight){

//     if(pt_data.find(idx) != pt_data.end()){
//         return ;
//     }

//     ll ans = 0;

//     int new_idx = bin_search_min(vec[idx], vec, idx+1, vec.size() - 1, weight);

//     if(!weight && new_idx == -1){

//         sum_table[idx] = 1;

//         pt_data[idx].first = 0;

//         if(vec[idx].first == vec[idx].second){
//             pt_data[idx].second = false;
//         }

//         else{
//             pt_data[idx].second = true;
//         }

//         return ;
//     }

//     else if(weight && new_idx == -1){

//         return ;
//     }

//     auto sz = sum_table.lower_bound(idx);
//     ll upl = vec.size(), ans = INF;

//     // getting the successor of the key

//     if(sz->second){
//         ans = sz->second - (vec[idx].second - vec[idx].first);
//         upl = sz->first; // We know minimum of all elements from sz->first......n, hence checking from
//                          // new_idx to sz->first only
//     }

//     while(new_idx < idx){

//         new_idx--;
//     }

// }

ll findMinimum(vector<pair<ll, ll> > vec, int idx){

    // cout << "BAM" << endl;
    if(memo.find(idx) != memo.end()){
        return memo[idx];
    }

    int new_idx = bin_search(vec[idx], vec, idx+1, (vec.size())-1);

    if(new_idx == -1){
        memo[idx] = vec[idx].first;
        dp[idx] = vec[idx].first;
        return vec[idx].first;
    }

    ll upl = vec.size(), ans = INF;

    for(int i = upl-1; i >= new_idx; i--){
        if(dp.find(i) == dp.end()){
            ans = min(ans, (findMinimum(vec, i)) - (vec[idx].second - vec[idx].first));
            dp.insert({i, ans});
        }
        else{
            ans = min(ans, dp[i] - (vec[idx].second - vec[idx].first));
        }
    }

    memo[idx] = ans;

    // cout << "memo[idx] for idx = " << idx << " is " << memo[idx] << endl;

    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    ll in, out, min_big_engh = INF, finAns = 0;

    cin >> n;

    vector<pair<ll, ll> > arr(n);

    for(int i = 0; i < n; i++){
        cin >> out >> in;

        arr[i].first = in;
        arr[i].second = out;

    }

    sort(arr.begin(), arr.end());

    for(int i = 0; i < n; i++){

        ll temp = findMinimum(arr, i);

        if(min_big_engh > temp){
            min_big_engh = temp;
        }
    }

    // cout << "min_big_engh is " << min_big_engh << endl;

    for(int i = 0; i < n; i++){
        if(sum_table.find(i) == sum_table.end()){
            int i_child = bin_search(arr[i], arr, i+1, arr.size() - 1);
            int opt_idx = sum_table_compute(arr, i, i_child, min_big_engh);
            finAns  = (finAns + sum_table[opt_idx])%mod;
            sum_table[i] = sum_table[i_child];
        }
    }

    cout << finAns << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define INF 1000000000000000000

unordered_map<int, ll> memo;
map<int, ll> dp, sum_table;
unordered_map<int, pair<int, bool> > pt_data;

ll power(ll m, ll n)
{
    if (n == 0)
        return 1;
    if(n == 1)
        return m%mod;
    else if(n%2)
    {
        ll res = ((power(m,(n/2)))%mod);
        return (((m*res)%mod)*res)%mod;
    }
    else
    {
        ll res = ((power(m,(n/2)))%mod);
        return (res*res)%mod;
    }
}

int bin_search(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j){

    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first >= num.second){

        int idx = bin_search(num, vec, i, mid-1);

        if(idx != -1)
            return idx;

        return mid;
    }

    else{
        return bin_search(num, vec, mid+1, j);
    }
}

// int bin_search_min(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j, ll weight){

//     if((j-i) < 0){
//         return -1;
//     }

//     int mid = i + ((j-i)/2);

//     if(vec[mid].first >= num.second){

//         if(weight > ((vec[mid].first) - (num.second - num.first)))
//             return bin_search_min(num, vec, i, mid-1, weight);

//         else{

//             int idx = bin_search_min(num, vec, i, mid-1, weight);

//             if(idx != -1)
//                 return idx;

//             return mid;
//         }
//     }

//     else{
//         return bin_search_min(num, vec, mid+1, j, weight);
//     }
// }

int sum_table_compute(vector<pair<ll, ll> > vec, int parent_idx, int idx ,ll weight){

    if((memo[idx] - (vec[parent_idx].second - vec[parent_idx].first)) > weight){
        int counter = bin_search(vec[parent_idx], vec, idx+1, (vec.size() - 1));

        if(counter != -1)
            return sum_table_compute(vec, parent_idx, counter, weight);
        else
            return -1;
    }

    else{

        if(sum_table.find(idx) != sum_table.end()){
            return idx;
        }

        int counter = bin_search(vec[parent_idx], vec, idx+1, (vec.size() - 1));

        sum_table[idx] = 0;

        if(vec[idx].first == vec[idx].second){
            if(counter != -1){

                int counter_idx = sum_table_compute(vec, parent_idx, counter, weight);
                if(counter_idx != -1){
                    if(pt_data[counter_idx].second){
                        pt_data[idx].first = 1;
                        pt_data[idx].second = true;
                        sum_table[idx] = (sum_table[idx] + 2*sum_table[counter_idx])%mod;
                    }
                    else{
                        pt_data[idx].first = 1;
                        pt_data[idx].second = false;
                        sum_table[idx] = sum_table[counter_idx]%mod;
                    }
                }

                else{
                    sum_table[idx] = 1;
                    pt_data[idx].first = 1;
                    pt_data[idx].second = false;
                }
            }

            else{
                sum_table[idx] = 1;
                pt_data[idx].first = 1;
                pt_data[idx].second = false;
            }
        }
        else{

            pt_data[idx].first = 1;
            pt_data[idx].second = true;

            int idx_child = bin_search(vec[idx], vec, idx+1, (vec.size() - 1));

            if(idx_child == -1){
                sum_table[idx] = 1;
            }

            else{
                int idx_child_child = sum_table_compute(vec, idx, idx_child, weight + (vec[idx].second - vec[idx].first));

                if(idx_child_child != -1){
                    sum_table[idx] = (sum_table[idx] + sum_table[idx_child_child])%mod;
                }
                else{
                    sum_table[idx] = 1;
                }
            }

            if(counter != -1){
                int counter_idx = sum_table_compute(vec, parent_idx, counter, weight);
                if(counter_idx != -1){
                    sum_table[idx] = (sum_table[idx] + sum_table[counter_idx])%mod;
                }
            }
        }

        return idx;
    }

}

// void solve(vector<pair<ll, ll> > vec, int idx, ll weight){

//     if(pt_data.find(idx) != pt_data.end()){
//         return ;
//     }

//     ll ans = 0;

//     int new_idx = bin_search_min(vec[idx], vec, idx+1, vec.size() - 1, weight);

//     if(!weight && new_idx == -1){

//         sum_table[idx] = 1;

//         pt_data[idx].first = 0;

//         if(vec[idx].first == vec[idx].second){
//             pt_data[idx].second = false;
//         }

//         else{
//             pt_data[idx].second = true;
//         }

//         return ;
//     }

//     else if(weight && new_idx == -1){

//         return ;
//     }

//     auto sz = sum_table.lower_bound(idx);
//     ll upl = vec.size(), ans = INF;

//     // getting the successor of the key

//     if(sz->second){
//         ans = sz->second - (vec[idx].second - vec[idx].first);
//         upl = sz->first; // We know minimum of all elements from sz->first......n, hence checking from
//                          // new_idx to sz->first only
//     }

//     while(new_idx < idx){

//         new_idx--;
//     }

// }

ll findMinimum(vector<pair<ll, ll> > vec, int idx){

    // cout << "BAM" << endl;
    if(memo.find(idx) != memo.end()){
        return memo[idx];
    }

    int new_idx = bin_search(vec[idx], vec, idx+1, (vec.size())-1);

    if(new_idx == -1){
        memo[idx] = vec[idx].first;
        dp[idx] = vec[idx].first;
        return vec[idx].first;
    }

    ll upl = vec.size(), ans = INF;

    for(int i = upl-1; i >= new_idx; i--){
        if(dp.find(i) == dp.end()){
            ans = min(ans, (findMinimum(vec, i)) - (vec[idx].second - vec[idx].first));
            dp.insert({i, ans});
        }
        else{
            ans = min(ans, dp[i] - (vec[idx].second - vec[idx].first));
        }
    }

    memo[idx] = ans;

    // cout << "memo[idx] for idx = " << idx << " is " << memo[idx] << endl;

    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    ll in, out, min_big_engh = INF, finAns = 0;

    cin >> n;

    vector<pair<ll, ll> > arr(n);

    for(int i = 0; i < n; i++){
        cin >> out >> in;

        arr[i].first = in;
        arr[i].second = out;

    }

    sort(arr.begin(), arr.end());

    for(int i = 0; i < n; i++){

        ll temp = findMinimum(arr, i);

        if(min_big_engh > temp){
            min_big_engh = temp;
        }
    }

    // cout << "min_big_engh is " << min_big_engh << endl;

    for(int i = 0; i < n; i++){
        if(sum_table.find(i) == sum_table.end()){
            int i_child = bin_search(arr[i], arr, i+1, arr.size() - 1);
            int opt_idx = sum_table_compute(arr, i, i_child, min_big_engh);
            if(opt_idx != -1){
                finAns  = (finAns + sum_table[opt_idx])%mod;
                sum_table[i] = sum_table[opt_idx];
            }
        }
    }

    cout << finAns << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define INF 1000000000000000000

unordered_map<int, ll> memo, dp, sum_table;
unordered_map<int, pair<int, bool> > pt_data;
vector<pair<ll, int> > sorted_memo;

int itCount = 0;

int stdrd_bin_search(ll num, pair<ll, int> pt, vector<pair<ll, int> > vec, int i, int j){
    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first == num){
        if(vec[mid].first >= pt.second){

            int idx = stdrd_bin_search(num, pt, vec, i, mid-1);

            if(idx != -1)
                return idx;

            return mid;
        }
        else{
            return stdrd_bin_search(num, pt, vec, mid+1, j);
        }
    }

    else if(vec[mid].first < num){
        return stdrd_bin_search(num, pt, vec, mid+1, j);
    }

    else{
        return stdrd_bin_search(num, pt, vec, i, mid-1);
    }
}

int bin_search(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j){

    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first >= num.second){

        int idx = bin_search(num, vec, i, mid-1);

        if(idx != -1)
            return idx;

        return mid;
    }

    else{
        return bin_search(num, vec, mid+1, j);
    }
}

ll sum_table_compute(vector<pair<ll, ll> > vec, int parent_idx, int idx, ll weight){

    // if((vec[parent_idx].second > vec[sorted_memo[idx].second].first)){
    //     return 0;
    // }

    // else{

        if(sum_table.find(sorted_memo[idx].second) != sum_table.end()){
            return sum_table[sorted_memo[idx].second];
        }

        else{

            sum_table[sorted_memo[idx].second] = 0;

            pair<ll, ll> vec_idx = vec[sorted_memo[idx].second];
            if(vec_idx.first == vec_idx.second){
                if(sorted_memo[idx + 1].first == weight){
                    ll next_cost = sum_table_compute(vec, parent_idx, idx+1, weight);

                    pt_data[sorted_memo[idx].second].second = pt_data[sorted_memo[idx+1].second].second;

                    if(pt_data[sorted_memo[idx].second].second){
                        sum_table[sorted_memo[idx].second] = (2*next_cost)%mod;
                    }
                    else{
                        sum_table[sorted_memo[idx].second] = 1;
                    }
                }

                else{
                    pt_data[sorted_memo[idx].second].second = false;
                    sum_table[sorted_memo[idx].second] = 1;
                }

                return sum_table[sorted_memo[idx].second];

            }
            else{
                pt_data[sorted_memo[idx].second].second = true;

                ll cost = weight + (vec_idx.second - vec_idx.first), child_cost;
                ll new_weight = weight + (vec_idx.second - vec_idx.first);
                ll child_idx = stdrd_bin_search(cost, vec[sorted_memo[idx].second], sorted_memo, 0, sorted_memo.size() - 1);

                if(child_idx != -1){
                    child_cost = sum_table_compute(vec, sorted_memo[idx].second, child_idx, new_weight);
                    if(child_cost)
                        sum_table[sorted_memo[idx].second] = child_cost%mod;
                    else
                        sum_table[sorted_memo[idx].second] = 1;
                }

                else{
                    sum_table[sorted_memo[idx].second] = 1;
                }

                if(sorted_memo[idx + 1].first == weight){

                    sum_table[sorted_memo[idx].second] = (sum_table[sorted_memo[idx].second] + (sum_table_compute(vec, parent_idx, idx+1, weight)))%mod;

                }

                return sum_table[sorted_memo[idx].second];
            }
        }

    // }

}

ll findMinimum(vector<pair<ll, ll> > vec, int idx){

    itCount++;
    if(memo.find(idx) != memo.end()){
        return memo[idx];
    }

    pair<ll, ll> vec_idx = vec[idx];

    int new_idx = bin_search(vec_idx, vec, idx+1, (vec.size())-1);
    if(new_idx == -1){
        memo[idx] = vec_idx.first;
        dp[idx] = vec_idx.first;
        return vec_idx.first;
    }

    ll upl = vec.size(), ans = INF, temp, tmp, prevMin = INF;

    for(int i = new_idx; i < upl; i++){
        if(dp.find(i) == dp.end()){
            temp = findMinimum(vec, i);
            tmp = temp - (vec_idx.second - vec_idx.first);
            if(ans > tmp){
                ans = tmp;
            }
        }
        else{
            ans = min(ans, dp[i] - (vec_idx.second - vec_idx.first));
            break;
        }
    }

    dp[new_idx] = ans + (vec_idx.second - vec_idx.first);
    memo[idx] = ans;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    ll in, out, min_big_engh = INF, finAns = 0;

    cin >> n;

    vector<pair<ll, ll> > arr(n);

    for(int i = 0; i < n; i++){
        cin >> out >> in;

        arr[i].first = in;
        arr[i].second = out;

    }

    if(n == 1){
        cout << 1 << endl;
        return 0;
    }

    sort(arr.begin(), arr.end());

    for(int i = 0; i < n; i++){

        ll temp = findMinimum(arr, i);

        if(min_big_engh > temp){
            min_big_engh = temp;
        }
    }

    for(int i = 0; i < n; i++){
        sorted_memo.push_back(make_pair(memo[i], i));
    }

    sort(sorted_memo.begin(), sorted_memo.end());

    // cout << "min_big_engh is " << min_big_engh << endl;
    // for(int i = 0; i < n; i++){
    //     cout << sorted_memo[i].first << " " << sorted_memo[i].second << endl;
    // }

    for(int i = 0; i < n; i++){
        if(sum_table.find(i) == sum_table.end()){
            int i_child = stdrd_bin_search(min_big_engh + (arr[i].second - arr[i].first), arr[i], sorted_memo, 0, arr.size() - 1);
            if(i_child != -1){
                // Check if returned index matches with the index we want to fit in the returned index
                // This will happen if index has no volume becaue then keeping it or removing it doesn't make a difference
                if(sorted_memo[i_child].second == i){
                    i_child++;
                }
                ll sum_i = sum_table_compute(arr, i, i_child, min_big_engh+(arr[i].second - arr[i].first));
                if(arr[i].first != arr[i].second)
                    finAns = (finAns + sum_i)%mod;
                else{
                    if(pt_data[sorted_memo[i_child].second].second){
                        finAns = (finAns + 2*sum_i)%mod;
                    }
                    else{
                        finAns = (finAns + 1)%mod;
                    }
                }
            }

            else{
                if(min_big_engh == arr[i].first){
                    finAns = (finAns + 1)%mod;
                }
            }
        }
    }

    // cout << "iteration count is " << itCount << endl;
    cout << finAns << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define INF 1000000000000000000

unordered_map<int, ll> memo, dp, sum_table;
unordered_map<int, pair<int, bool> > pt_data;
vector<pair<ll, int> > sorted_memo;

int itCount = 0;
ll power(ll m, ll n)
{
    if (n == 0)
        return 1;
    if(n == 1)
        return m%mod;
    else if(n%2)
    {
        ll res = ((power(m,(n/2)))%mod);
        return (((m*res)%mod)*res)%mod;
    }
    else{
        ll res = ((power(m,(n/2)))%mod);
        return (res*res)%mod;
    }
}

int stdrd_bin_search(ll num, pair<ll, int> pt, vector<pair<ll, int> > vec, int i, int j){
    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first == num){
        if(vec[mid].first >= pt.second){

            int idx = stdrd_bin_search(num, pt, vec, i, mid-1);

            if(idx != -1)
                return idx;

            return mid;
        }
        else{
            return stdrd_bin_search(num, pt, vec, mid+1, j);
        }
    }

    else if(vec[mid].first < num){
        return stdrd_bin_search(num, pt, vec, mid+1, j);
    }

    else{
        return stdrd_bin_search(num, pt, vec, i, mid-1);
    }
}

int bin_search(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j){

    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first >= num.second){

        int idx = bin_search(num, vec, i, mid-1);

        if(idx != -1)
            return idx;

        return mid;
    }

    else{
        return bin_search(num, vec, mid+1, j);
    }
}

ll sum_table_compute(vector<pair<ll, ll> > vec, int parent_idx, int idx, ll weight){
    // itCount++;

    if((vec[parent_idx].second > vec[sorted_memo[idx].second].first)){
        return 0;
    }

    else{

        if(sum_table.find(sorted_memo[idx].second) != sum_table.end()){
            return sum_table[sorted_memo[idx].second];
        }

        else{

            sum_table[sorted_memo[idx].second] = 0;

            pair<ll, ll> vec_idx = vec[sorted_memo[idx].second];

            if(vec_idx.first == vec_idx.second){
                if(sorted_memo[idx + 1].first == weight){
                    ll next_cost = sum_table_compute(vec, parent_idx, idx+1, weight);

                    pt_data[sorted_memo[idx].second].second = pt_data[sorted_memo[idx+1].second].second;

                    if(pt_data[sorted_memo[idx].second].second){
                        sum_table[sorted_memo[idx].second] = (2*next_cost)%mod;
                    }
                    else{
                        sum_table[sorted_memo[idx].second] = 1;
                    }
                }

                else{
                    pt_data[sorted_memo[idx].second].second = false;
                    sum_table[sorted_memo[idx].second] = 1;
                }

                return sum_table[sorted_memo[idx].second];

            }
            else{
                pt_data[sorted_memo[idx].second].second = true;

                ll cost = weight + (vec_idx.second - vec_idx.first), child_cost;
                ll new_weight = weight + (vec_idx.second - vec_idx.first);
                ll child_idx = stdrd_bin_search(cost, vec[sorted_memo[idx].second], sorted_memo, 0, sorted_memo.size() - 1);

                if(child_idx != -1){
                    child_cost = sum_table_compute(vec, sorted_memo[idx].second, child_idx, new_weight);
                    if(child_cost)
                        sum_table[sorted_memo[idx].second] = child_cost%mod;
                    else
                        sum_table[sorted_memo[idx].second] = 1;
                }

                else{
                    sum_table[sorted_memo[idx].second] = 1;
                }

                if(sorted_memo[idx + 1].first == weight){

                    sum_table[sorted_memo[idx].second] = (sum_table[sorted_memo[idx].second] + (sum_table_compute(vec, parent_idx, idx+1, weight)))%mod;

                }

                return sum_table[sorted_memo[idx].second];
            }
        }

    }

}

// void solve(vector<pair<ll, ll> > vec, int idx, ll weight){

//     if(pt_data.find(idx) != pt_data.end()){
//         return ;
//     }

//     ll ans = 0;

//     int new_idx = bin_search_min(vec[idx], vec, idx+1, vec.size() - 1, weight);

//     if(!weight && new_idx == -1){

//         sum_table[idx] = 1;

//         pt_data[idx].first = 0;

//         if(vec[idx].first == vec[idx].second){
//             pt_data[idx].second = false;
//         }

//         else{
//             pt_data[idx].second = true;
//         }

//         return ;
//     }

//     else if(weight && new_idx == -1){

//         return ;
//     }

//     auto sz = sum_table.lower_bound(idx);
//     ll upl = vec.size(), ans = INF;

//     // getting the successor of the key

//     if(sz->second){
//         ans = sz->second - (vec[idx].second - vec[idx].first);
//         upl = sz->first; // We know minimum of all elements from sz->first......n, hence checking from
//                          // new_idx to sz->first only
//     }

//     while(new_idx < idx){

//         new_idx--;
//     }

// }

ll findMinimum(vector<pair<ll, ll> > vec, int idx){

    if(memo.find(idx) != memo.end()){
        return memo[idx];
    }

    pair<ll, ll> vec_idx = vec[idx];

    int new_idx = bin_search(vec_idx, vec, idx+1, (vec.size())-1);
    if(new_idx == -1){
        memo[idx] = vec_idx.first;
        dp[idx] = vec_idx.first;
        return vec_idx.first;
    }

    ll upl = vec.size(), ans = INF, temp, tmp, prevMin = INF;

    for(int i = new_idx; i < upl; i++){
        if(dp.find(i) == dp.end()){
            temp = findMinimum(vec, i);
            tmp = temp - (vec_idx.second - vec_idx.first);
            if(ans > tmp){
                ans = tmp;
            }
        }
        else{
            ans = min(ans, dp[i] - (vec_idx.second - vec_idx.first));
            break;
        }
    }

    dp[new_idx] = ans + (vec_idx.second - vec_idx.first);
    memo[idx] = ans;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    ll in, out, min_big_engh = INF, finAns = 0;

    cin >> n;

    vector<pair<ll, ll> > arr(n);

    for(int i = 0; i < n; i++){
        cin >> out >> in;

        arr[i].first = in;
        arr[i].second = out;

    }

    sort(arr.begin(), arr.end());

    for(int i = 0; i < n; i++){

        ll temp = findMinimum(arr, i);

        if(min_big_engh > temp){
            min_big_engh = temp;
        }
    }

    for(int i = 0; i < n; i++){
        sorted_memo.push_back(make_pair(memo[i], i));
    }

    sort(sorted_memo.begin(), sorted_memo.end());

    // cout << "min_big_engh is " << min_big_engh << endl;
    // for(int i = 0; i < n; i++){
    //     cout << sorted_memo[i].first << " " << sorted_memo[i].second << endl;
    // }

    for(int i = 0; i < n; i++){
        if(sum_table.find(i) == sum_table.end()){
            int i_child = stdrd_bin_search(min_big_engh + (arr[i].second - arr[i].first), arr[i], sorted_memo, 0, arr.size() - 1);
            if(i_child != -1){
                ll sum_i = sum_table_compute(arr, i, i_child, min_big_engh+(arr[i].second - arr[i].first));
                if(arr[i].first != arr[i].second)
                    finAns = (finAns + sum_i)%mod;
                else{
                    if(pt_data[sorted_memo[i_child].second].second){
                        finAns = (finAns + 2*sum_i)%mod;
                    }
                    else{
                        finAns = (finAns + 1)%mod;
                    }
                }
            }

            else{
                if(min_big_engh == arr[i].first){
                    finAns = (finAns + 1)%mod;
                }
            }
        }
    }

    // cout << "iteration count is " << itCount << endl;
    cout << finAns << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define INF 1000000000000000000

unordered_map<int, ll> memo, dp, sum_table;
unordered_map<int, pair<int, bool> > pt_data;
vector<pair<ll, int> > sorted_memo;

int itCount = 0;

int stdrd_bin_search(ll num, pair<ll, ll> pt, vector<pair<ll, int> > vec, vector<pair<ll, ll> > pt_vec, int i, int j){
    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first == num){
        if(pt_vec[vec[mid].second].first >= pt.second){

            int idx = stdrd_bin_search(num, pt, vec, pt_vec, i, mid-1);

            if(idx != -1)
                return idx;

            return mid;
        }
        else{
            return stdrd_bin_search(num, pt, vec, pt_vec, mid+1, j);
        }
    }

    else if(vec[mid].first < num){
        return stdrd_bin_search(num, pt, vec, pt_vec, mid+1, j);
    }

    else{
        return stdrd_bin_search(num, pt, vec, pt_vec, i, mid-1);
    }
}

int bin_search(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j){

    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first >= num.second){

        int idx = bin_search(num, vec, i, mid-1);

        if(idx != -1)
            return idx;

        return mid;
    }

    else{
        return bin_search(num, vec, mid+1, j);
    }
}

ll sum_table_compute(vector<pair<ll, ll> > vec, int parent_idx, int idx, ll weight){

    if(sum_table.find(sorted_memo[idx].second) != sum_table.end()){
        return sum_table[sorted_memo[idx].second];
    }

    else{

        sum_table[sorted_memo[idx].second] = 0;

        pair<ll, ll> vec_idx = vec[sorted_memo[idx].second];
        if(vec_idx.first == vec_idx.second){
            if((idx < (vec.size()-1)) && sorted_memo[idx + 1].first == weight){
                ll next_cost = sum_table_compute(vec, parent_idx, idx+1, weight);

                pt_data[sorted_memo[idx].second].second = pt_data[sorted_memo[idx+1].second].second;

                if(pt_data[sorted_memo[idx].second].second){
                    sum_table[sorted_memo[idx].second] = (2*next_cost)%mod;
                }
                else{
                    sum_table[sorted_memo[idx].second] = 1;
                }
            }

            else{
                pt_data[sorted_memo[idx].second].second = false;
                sum_table[sorted_memo[idx].second] = 1;
            }

            return sum_table[sorted_memo[idx].second];

        }
        else{
            pt_data[sorted_memo[idx].second].second = true;

            ll cost = weight + (vec_idx.second - vec_idx.first), child_cost;
            ll new_weight = weight + (vec_idx.second - vec_idx.first);
            ll child_idx = stdrd_bin_search(cost, vec[sorted_memo[idx].second], sorted_memo, vec, 0, sorted_memo.size() - 1);

            if(child_idx != -1){
                child_cost = sum_table_compute(vec, sorted_memo[idx].second, child_idx, new_weight);
                if(child_cost)
                    sum_table[sorted_memo[idx].second] = child_cost%mod;
                else
                    sum_table[sorted_memo[idx].second] = 1;
            }

            else{
                sum_table[sorted_memo[idx].second] = 1;
            }

            if((idx < (vec.size()-1)) && sorted_memo[idx + 1].first == weight){

                sum_table[sorted_memo[idx].second] = (sum_table[sorted_memo[idx].second] + (sum_table_compute(vec, parent_idx, idx+1, weight)))%mod;

            }

            return sum_table[sorted_memo[idx].second];
        }
    }

}

ll findMinimum(vector<pair<ll, ll> > vec, int idx){

    itCount++;
    if(memo.find(idx) != memo.end()){
        return memo[idx];
    }

    pair<ll, ll> vec_idx = vec[idx];

    int new_idx = bin_search(vec_idx, vec, idx+1, (vec.size())-1);
    if(new_idx == -1){
        memo[idx] = vec_idx.first;
        dp[idx] = vec_idx.first;
        return vec_idx.first;
    }

    ll upl = vec.size(), ans = INF, temp, tmp, prevMin = INF;

    for(int i = new_idx; i < upl; i++){
        if(dp.find(i) == dp.end()){
            temp = findMinimum(vec, i);
            tmp = temp - (vec_idx.second - vec_idx.first);
            if(ans > tmp){
                ans = tmp;
            }
        }
        else{
            ans = min(ans, dp[i] - (vec_idx.second - vec_idx.first));
            break;
        }
    }

    dp[new_idx] = ans + (vec_idx.second - vec_idx.first);
    memo[idx] = ans;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    ll in, out, min_big_engh = INF, finAns = 0;

    cin >> n;

    vector<pair<ll, ll> > arr(n);

    for(int i = 0; i < n; i++){
        cin >> out >> in;

        arr[i].first = in;
        arr[i].second = out;

    }

    if(n == 1){
        cout << 1 << endl;
        return 0;
    }

    sort(arr.begin(), arr.end());

    for(int i = 0; i < n; i++){

        ll temp = findMinimum(arr, i);

        if(min_big_engh > temp){
            min_big_engh = temp;
        }
    }

    for(int i = 0; i < n; i++){
        sorted_memo.push_back(make_pair(memo[i], i));
    }

    sort(sorted_memo.begin(), sorted_memo.end());

    // cout << "min_big_engh is " << min_big_engh << endl;
    // for(int i = 0; i < n; i++){
    //     cout << sorted_memo[i].first << " " << sorted_memo[i].second << endl;
    // }

    for(int i = 0; i < n; i++){
        if(sum_table.find(i) == sum_table.end()){
            int i_child = stdrd_bin_search(min_big_engh + (arr[i].second - arr[i].first), arr[i], sorted_memo, arr, 0, arr.size() - 1);
            if(i_child != -1){
                // Check if returned index matches with the index we want to fit in the returned index
                // This will happen if index has no volume becaue then keeping it or removing it doesn't make a difference
                if(sorted_memo[i_child].second == i){
                    i_child++;
                }
                ll sum_i = sum_table_compute(arr, i, i_child, min_big_engh+(arr[i].second - arr[i].first));
                if(arr[i].first != arr[i].second)
                    finAns = (finAns + sum_i)%mod;
                else{
                    if(pt_data[sorted_memo[i_child].second].second){
                        finAns = (finAns + 2*sum_i)%mod;
                    }
                    else{
                        finAns = (finAns + 1)%mod;
                    }
                }
            }

            else{
                int child_idx = bin_search(arr[i], arr, i+1, (arr.size()-1));
                if((child_idx == -1) && min_big_engh == arr[i].first){
                    finAns = (finAns + 1)%mod;
                }
            }
        }
    }

    // cout << "iteration count is " << itCount << endl;
    cout << finAns << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define INF 1000000000000000000

unordered_map<int, ll> memo;
map<int, ll> dp, sum_table;
unordered_map<int, pair<int, bool> > pt_data;

ll power(ll m, ll n)
{
    if (n == 0)
        return 1;
    if(n == 1)
        return m%mod;
    else if(n%2)
    {
        ll res = ((power(m,(n/2)))%mod);
        return (((m*res)%mod)*res)%mod;
    }
    else
    {
        ll res = ((power(m,(n/2)))%mod);
        return (res*res)%mod;
    }
}

int bin_search(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j){

    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first >= num.second){

        int idx = bin_search(num, vec, i, mid-1);

        if(idx != -1)
            return idx;

        return mid;
    }

    else{
        return bin_search(num, vec, mid+1, j);
    }
}

// int bin_search_min(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j, ll weight){

//     if((j-i) < 0){
//         return -1;
//     }

//     int mid = i + ((j-i)/2);

//     if(vec[mid].first >= num.second){

//         if(weight > ((vec[mid].first) - (num.second - num.first)))
//             return bin_search_min(num, vec, i, mid-1, weight);

//         else{

//             int idx = bin_search_min(num, vec, i, mid-1, weight);

//             if(idx != -1)
//                 return idx;

//             return mid;
//         }
//     }

//     else{
//         return bin_search_min(num, vec, mid+1, j, weight);
//     }
// }

int sum_table_compute(vector<pair<ll, ll> > vec, int parent_idx, int idx ,ll weight){

    if((memo[idx] - (vec[parent_idx].second - vec[parent_idx].first)) > weight){
        int counter = bin_search(vec[parent_idx], vec, idx+1, (vec.size() - 1));

        if(counter != -1)
            return sum_table_compute(vec, parent_idx, counter, weight);
        else
            return -1;
    }

    else{

        if(sum_table.find(idx) != sum_table.end()){
            return idx;
        }

        int counter = bin_search(vec[parent_idx], vec, idx+1, (vec.size() - 1));

        sum_table[idx] = 0;

        if(vec[idx].first == vec[idx].second){
            if(counter != -1){

                int counter_idx = sum_table_compute(vec, parent_idx, counter, weight);
                if(counter_idx != -1){
                    if(pt_data[counter_idx].second){
                        pt_data[idx].first = 1;
                        pt_data[idx].second = true;
                        sum_table[idx] = (sum_table[idx] + 2*sum_table[counter_idx])%mod;
                    }
                    else{
                        pt_data[idx].first = 1;
                        pt_data[idx].second = false;
                        sum_table[idx] = sum_table[counter_idx]%mod;
                    }
                }

                else{
                    sum_table[idx] = 1;
                    pt_data[idx].first = 1;
                    pt_data[idx].second = false;
                }
            }

            else{
                sum_table[idx] = 1;
                pt_data[idx].first = 1;
                pt_data[idx].second = false;
            }
        }
        else{

            pt_data[idx].first = 1;
            pt_data[idx].second = true;

            int idx_child = bin_search(vec[idx], vec, idx+1, (vec.size() - 1));

            if(idx_child == -1){
                sum_table[idx] = 1;
            }

            else{
                int idx_child_child = sum_table_compute(vec, idx, idx_child, weight + (vec[idx].second - vec[idx].first));

                if(idx_child_child != -1){
                    sum_table[idx] = (sum_table[idx] + sum_table[idx_child_child])%mod;
                }
                else{
                    sum_table[idx] = 1;
                }
            }

            if(counter != -1){
                int counter_idx = sum_table_compute(vec, parent_idx, counter, weight);
                if(counter_idx != -1){
                    sum_table[idx] = (sum_table[idx] + sum_table[counter_idx])%mod;
                }
            }
        }

        return idx;
    }

}

// void solve(vector<pair<ll, ll> > vec, int idx, ll weight){

//     if(pt_data.find(idx) != pt_data.end()){
//         return ;
//     }

//     ll ans = 0;

//     int new_idx = bin_search_min(vec[idx], vec, idx+1, vec.size() - 1, weight);

//     if(!weight && new_idx == -1){

//         sum_table[idx] = 1;

//         pt_data[idx].first = 0;

//         if(vec[idx].first == vec[idx].second){
//             pt_data[idx].second = false;
//         }

//         else{
//             pt_data[idx].second = true;
//         }

//         return ;
//     }

//     else if(weight && new_idx == -1){

//         return ;
//     }

//     auto sz = sum_table.lower_bound(idx);
//     ll upl = vec.size(), ans = INF;

//     // getting the successor of the key

//     if(sz->second){
//         ans = sz->second - (vec[idx].second - vec[idx].first);
//         upl = sz->first; // We know minimum of all elements from sz->first......n, hence checking from
//                          // new_idx to sz->first only
//     }

//     while(new_idx < idx){

//         new_idx--;
//     }

// }

ll findMinimum(vector<pair<ll, ll> > vec, int idx){

    // cout << "BAM" << endl;
    if(memo.find(idx) != memo.end()){
        return memo[idx];
    }

    int new_idx = bin_search(vec[idx], vec, idx+1, (vec.size())-1);

    if(new_idx == -1){
        memo[idx] = vec[idx].first;
        dp[idx] = vec[idx].first;
        return vec[idx].first;
    }

    ll upl = vec.size(), ans = INF;

    for(int i = upl-1; i >= new_idx; i--){
        if(dp.find(i) == dp.end()){
            ans = min(ans, (findMinimum(vec, i)) - (vec[idx].second - vec[idx].first));
            dp.insert({i, ans});
        }
        else{
            ans = min(ans, dp[i] - (vec[idx].second - vec[idx].first));
        }
    }

    memo[idx] = ans;

    // cout << "memo[idx] for idx = " << idx << " is " << memo[idx] << endl;

    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    ll in, out, min_big_engh = INF, finAns = 0;

    cin >> n;

    vector<pair<ll, ll> > arr(n);

    for(int i = 0; i < n; i++){
        cin >> out >> in;

        arr[i].first = in;
        arr[i].second = out;

    }

    sort(arr.begin(), arr.end());

    for(int i = 0; i < n; i++){

        ll temp = findMinimum(arr, i);

        if(min_big_engh > temp){
            min_big_engh = temp;
        }
    }

    // cout << "min_big_engh is " << min_big_engh << endl;

    for(int i = 0; i < n; i++){
        if(sum_table.find(i) == sum_table.end()){
            int i_child = bin_search(arr[i], arr, i+1, arr.size() - 1);
            int opt_idx = sum_table_compute(arr, i, i_child, min_big_engh);
            if(opt_idx != -1){
                finAns  = (finAns + sum_table[opt_idx])%mod;
                sum_table[i] = sum_table[i_child];
            }
        }
    }

    cout << finAns << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define INF 1000000000000000000

unordered_map<int, ll> memo;
map<int, ll> dp, sum_table;
unordered_map<int, pair<int, bool> > pt_data;

ll power(ll m, ll n)
{
    if (n == 0)
        return 1;
    if(n == 1)
        return m%mod;
    else if(n%2)
    {
        ll res = ((power(m,(n/2)))%mod);
        return (((m*res)%mod)*res)%mod;
    }
    else
    {
        ll res = ((power(m,(n/2)))%mod);
        return (res*res)%mod;
    }
}

int bin_search(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j){

    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first >= num.second){

        int idx = bin_search(num, vec, i, mid-1);

        if(idx != -1)
            return idx;

        return mid;
    }

    else{
        return bin_search(num, vec, mid+1, j);
    }
}

// int bin_search_min(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j, ll weight){

//     if((j-i) < 0){
//         return -1;
//     }

//     int mid = i + ((j-i)/2);

//     if(vec[mid].first >= num.second){

//         if(weight > ((vec[mid].first) - (num.second - num.first)))
//             return bin_search_min(num, vec, i, mid-1, weight);

//         else{

//             int idx = bin_search_min(num, vec, i, mid-1, weight);

//             if(idx != -1)
//                 return idx;

//             return mid;
//         }
//     }

//     else{
//         return bin_search_min(num, vec, mid+1, j, weight);
//     }
// }

int sum_table_compute(vector<pair<ll, ll> > vec, int parent_idx, int idx ,ll weight){

    if((memo[idx] - (vec[parent_idx].second - vec[parent_idx].first)) > weight){
        int counter = bin_search(vec[parent_idx], vec, idx+1, (vec.size() - 1));

        if(counter != -1)
            return sum_table_compute(vec, parent_idx, counter, weight);
        else
            return -1;
    }

    else{

        if(sum_table.find(idx) != sum_table.end()){
            return idx;
        }

        int counter = bin_search(vec[parent_idx], vec, idx+1, (vec.size() - 1));

        sum_table[idx] = 0;

        if(vec[idx].first == vec[idx].second){
            if(counter != -1){

                int counter_idx = sum_table_compute(vec, parent_idx, counter, weight);
                if(counter_idx != -1){
                    if(pt_data[counter_idx].second){
                        pt_data[idx].first = 1;
                        pt_data[idx].second = true;
                        sum_table[idx] = (sum_table[idx] + 2*sum_table[counter_idx])%mod;
                    }
                    else{
                        pt_data[idx].first = 1;
                        pt_data[idx].second = false;
                        sum_table[idx] = sum_table[counter_idx]%mod;
                    }
                }

                else{
                    sum_table[idx] = 1;
                    pt_data[idx].first = 1;
                    pt_data[idx].second = false;
                }
            }

            else{
                sum_table[idx] = 1;
                pt_data[idx].first = 1;
                pt_data[idx].second = false;
            }
        }
        else{

            pt_data[idx].first = 1;
            pt_data[idx].second = true;

            int idx_child = bin_search(vec[idx], vec, idx+1, (vec.size() - 1));

            if(idx_child == -1){
                sum_table[idx] = 1;
            }

            else{
                int idx_child_child = sum_table_compute(vec, idx, idx_child, weight + (vec[idx].second - vec[idx].first));

                if(idx_child_child != -1){
                    sum_table[idx] = (sum_table[idx] + sum_table[idx_child_child])%mod;
                }
                else{
                    sum_table[idx] = 1;
                }
            }

            if(counter != -1){
                int counter_idx = sum_table_compute(vec, parent_idx, counter, weight);
                if(counter_idx != -1){
                    sum_table[idx] = (sum_table[idx] + sum_table[counter_idx])%mod;
                }
            }
        }

        return idx;
    }

}

// void solve(vector<pair<ll, ll> > vec, int idx, ll weight){

//     if(pt_data.find(idx) != pt_data.end()){
//         return ;
//     }

//     ll ans = 0;

//     int new_idx = bin_search_min(vec[idx], vec, idx+1, vec.size() - 1, weight);

//     if(!weight && new_idx == -1){

//         sum_table[idx] = 1;

//         pt_data[idx].first = 0;

//         if(vec[idx].first == vec[idx].second){
//             pt_data[idx].second = false;
//         }

//         else{
//             pt_data[idx].second = true;
//         }

//         return ;
//     }

//     else if(weight && new_idx == -1){

//         return ;
//     }

//     auto sz = sum_table.lower_bound(idx);
//     ll upl = vec.size(), ans = INF;

//     // getting the successor of the key

//     if(sz->second){
//         ans = sz->second - (vec[idx].second - vec[idx].first);
//         upl = sz->first; // We know minimum of all elements from sz->first......n, hence checking from
//                          // new_idx to sz->first only
//     }

//     while(new_idx < idx){

//         new_idx--;
//     }

// }

ll findMinimum(vector<pair<ll, ll> > vec, int idx){

    if(memo.find(idx) != memo.end()){
        return memo[idx];
    }

    int new_idx = bin_search(vec[idx], vec, idx+1, (vec.size())-1);

    if(new_idx == -1){
        memo[idx] = vec[idx].first;
        dp[idx] = vec[idx].first;
        return vec[idx].first;
    }

    ll upl = vec.size(), ans = INF, temp, tmp;

    for(int i = new_idx; i < upl; i++){
        if(dp.find(i) == dp.end()){
            temp = findMinimum(vec, i);
            tmp = temp - (vec[idx].second - vec[idx].first);
            if(ans > tmp){
                ans = tmp;
                dp[i] = temp;
            }
            else{
                dp[i] = dp[i-1];
            }
        }
        else{
            ans = min(ans, dp[i] - (vec[idx].second - vec[idx].first));
            break;
        }
    }

    memo[idx] = ans;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    ll in, out, min_big_engh = INF, finAns = 0;

    cin >> n;

    vector<pair<ll, ll> > arr(n);

    for(int i = 0; i < n; i++){
        cin >> out >> in;

        arr[i].first = in;
        arr[i].second = out;

    }

    sort(arr.begin(), arr.end());

    for(int i = 0; i < n; i++){

        ll temp = findMinimum(arr, i);

        if(min_big_engh > temp){
            min_big_engh = temp;
        }
    }

    for(int i = 0; i < n; i++){
        if(sum_table.find(i) == sum_table.end()){
            int i_child = bin_search(arr[i], arr, i+1, arr.size() - 1);
            if(i_child != -1){
                int opt_idx = sum_table_compute(arr, i, i_child, min_big_engh);
                if(opt_idx != -1){
                    finAns  = (finAns + sum_table[opt_idx])%mod;
                    sum_table[i] = sum_table[opt_idx];
                }
            }

            else{
                if(min_big_engh == arr[i].first){
                    finAns = (finAns + 1)%mod;
                }
            }
        }
    }

    cout << finAns << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define INF 1000000000000000000

unordered_map<int, ll> memo, dp, sum_table;
unordered_map<int, pair<int, bool> > pt_data;
vector<pair<ll, int> > sorted_memo;

int itCount = 0;

int stdrd_bin_search(ll num, pair<ll, ll> pt, vector<pair<ll, int> > vec, vector<pair<ll, ll> > pt_vec, int i, int j){
    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first == num){
        if(pt_vec[vec[mid].second].first >= pt.second){

            int idx = stdrd_bin_search(num, pt, vec, pt_vec, i, mid-1);

            if(idx != -1)
                return idx;

            return mid;
        }
        else{
            return stdrd_bin_search(num, pt, vec, pt_vec, mid+1, j);
        }
    }

    else if(vec[mid].first < num){
        return stdrd_bin_search(num, pt, vec, pt_vec, mid+1, j);
    }

    else{
        return stdrd_bin_search(num, pt, vec, pt_vec, i, mid-1);
    }
}

int bin_search(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j){

    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first >= num.second){

        int idx = bin_search(num, vec, i, mid-1);

        if(idx != -1)
            return idx;

        return mid;
    }

    else{
        return bin_search(num, vec, mid+1, j);
    }
}

ll sum_table_compute(vector<pair<ll, ll> > vec, int parent_idx, int idx, ll weight){

    if(sum_table.find(sorted_memo[idx].second) != sum_table.end()){
        return sum_table[sorted_memo[idx].second];
    }

    else{

        sum_table[sorted_memo[idx].second] = 0;

        pair<ll, ll> vec_idx = vec[sorted_memo[idx].second];
        if(vec_idx.first == vec_idx.second){
            if((idx < (vec.size()-1)) && sorted_memo[idx + 1].first == weight){
                ll next_cost = sum_table_compute(vec, parent_idx, idx+1, weight);

                pt_data[sorted_memo[idx].second].second = pt_data[sorted_memo[idx+1].second].second;

                if(pt_data[sorted_memo[idx].second].second){
                    sum_table[sorted_memo[idx].second] = (2*next_cost)%mod;
                }
                else{
                    sum_table[sorted_memo[idx].second] = 1;
                }
            }

            else{
                pt_data[sorted_memo[idx].second].second = false;
                sum_table[sorted_memo[idx].second] = 1;
            }

            return sum_table[sorted_memo[idx].second];

        }
        else{
            pt_data[sorted_memo[idx].second].second = true;

            ll cost = weight + (vec_idx.second - vec_idx.first), child_cost;
            ll new_weight = weight + (vec_idx.second - vec_idx.first);
            ll child_idx = stdrd_bin_search(cost, vec[sorted_memo[idx].second], sorted_memo, vec, 0, sorted_memo.size() - 1);

            if(child_idx != -1){
                child_cost = sum_table_compute(vec, sorted_memo[idx].second, child_idx, new_weight);
                if(child_cost)
                    sum_table[sorted_memo[idx].second] = child_cost%mod;
                else
                    sum_table[sorted_memo[idx].second] = 1;
            }

            else{
                sum_table[sorted_memo[idx].second] = 1;
            }

            if((idx < (vec.size()-1)) && sorted_memo[idx + 1].first == weight){

                sum_table[sorted_memo[idx].second] = (sum_table[sorted_memo[idx].second] + (sum_table_compute(vec, parent_idx, idx+1, weight)))%mod;

            }

            return sum_table[sorted_memo[idx].second];
        }
    }

}

ll findMinimum(vector<pair<ll, ll> > vec, int idx){

    itCount++;
    if(memo.find(idx) != memo.end()){
        return memo[idx];
    }

    pair<ll, ll> vec_idx = vec[idx];

    int new_idx = bin_search(vec_idx, vec, idx+1, (vec.size())-1);
    if(new_idx == -1){
        memo[idx] = vec_idx.first;
        dp[idx] = vec_idx.first;
        return vec_idx.first;
    }

    ll upl = vec.size(), ans = INF, temp, tmp, prevMin = INF;

    for(int i = new_idx; i < upl; i++){
        if(dp.find(i) == dp.end()){
            temp = findMinimum(vec, i);
            tmp = temp - (vec_idx.second - vec_idx.first);
            if(ans > tmp){
                ans = tmp;
            }
        }
        else{
            ans = min(ans, dp[i] - (vec_idx.second - vec_idx.first));
            break;
        }
    }

    dp[new_idx] = ans + (vec_idx.second - vec_idx.first);
    memo[idx] = ans;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    ll in, out, min_big_engh = INF, finAns = 0;

    cin >> n;

    vector<pair<ll, ll> > arr(n);

    for(int i = 0; i < n; i++){
        cin >> out >> in;

        arr[i].first = in;
        arr[i].second = out;

    }

    if(n == 1){
        cout << 1 << endl;
        return 0;
    }

    sort(arr.begin(), arr.end());

    for(int i = 0; i < n; i++){

        ll temp = findMinimum(arr, i);

        if(min_big_engh > temp){
            min_big_engh = temp;
        }
    }

    for(int i = 0; i < n; i++){
        sorted_memo.push_back(make_pair(memo[i], i));
    }

    sort(sorted_memo.begin(), sorted_memo.end());

    // cout << "min_big_engh is " << min_big_engh << endl;
    // for(int i = 0; i < n; i++){
    //     cout << sorted_memo[i].first << " " << sorted_memo[i].second << endl;
    // }

    for(int i = 0; i < n; i++){
        if(sum_table.find(i) == sum_table.end()){
            int i_child = stdrd_bin_search(min_big_engh + (arr[i].second - arr[i].first), arr[i], sorted_memo, arr, 0, arr.size() - 1);
            if(i_child != -1){
                // Check if returned index matches with the index we want to fit in the returned index
                // This will happen if index has no volume becaue then keeping it or removing it doesn't make a difference
                if(sorted_memo[i_child].second == i){
                    i_child++;
                }
                ll sum_i = sum_table_compute(arr, i, i_child, min_big_engh+(arr[i].second - arr[i].first));
                if(arr[i].first != arr[i].second)
                    finAns = (finAns + sum_i)%mod;
                else{
                    if(pt_data[sorted_memo[i_child].second].second){
                        finAns = (finAns + 2*sum_i)%mod;
                    }
                    else{
                        finAns = (finAns + 1)%mod;
                    }
                }
            }

            else{
                if(min_big_engh == arr[i].first){
                    finAns = (finAns + 1)%mod;
                }
            }
        }
    }

    // cout << "iteration count is " << itCount << endl;
    cout << finAns << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define INF 1000000000000000000

unordered_map<int, ll> memo, dp, sum_table;
unordered_map<int, pair<int, bool> > pt_data;
vector<pair<ll, int> > sorted_memo;

int itCount = 0;
ll power(ll m, ll n)
{
    if (n == 0)
        return 1;
    if(n == 1)
        return m%mod;
    else if(n%2)
    {
        ll res = ((power(m,(n/2)))%mod);
        return (((m*res)%mod)*res)%mod;
    }
    else{
        ll res = ((power(m,(n/2)))%mod);
        return (res*res)%mod;
    }
}

int stdrd_bin_search(ll num, pair<ll, int> pt, vector<pair<ll, int> > vec, int i, int j){
    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first == num){
        if(vec[mid].first >= pt.second){

            int idx = stdrd_bin_search(num, pt, vec, i, mid-1);

            if(idx != -1)
                return idx;

            return mid;
        }
        else{
            return stdrd_bin_search(num, pt, vec, mid+1, j);
        }
    }

    else if(vec[mid].first < num){
        return stdrd_bin_search(num, pt, vec, mid+1, j);
    }

    else{
        return stdrd_bin_search(num, pt, vec, i, mid-1);
    }
}

int bin_search(pair<ll, ll> num, vector<pair<ll, ll> > vec, int i, int j){

    if((j-i) < 0){
        return -1;
    }

    int mid = i + ((j-i)/2);

    if(vec[mid].first >= num.second){

        int idx = bin_search(num, vec, i, mid-1);

        if(idx != -1)
            return idx;

        return mid;
    }

    else{
        return bin_search(num, vec, mid+1, j);
    }
}

ll sum_table_compute(vector<pair<ll, ll> > vec, int parent_idx, int idx, ll weight){
    itCount++;

    if((vec[parent_idx].second > vec[sorted_memo[idx].second].first)){
        return 0;
    }

    else{

        if(sum_table.find(sorted_memo[idx].second) != sum_table.end()){
            return sum_table[sorted_memo[idx].second];
        }

        else{

            sum_table[sorted_memo[idx].second] = 0;

            pair<ll, ll> vec_idx = vec[sorted_memo[idx].second];

            if(vec_idx.first == vec_idx.second){
                if(sorted_memo[idx + 1].first == weight){
                    ll next_cost = sum_table_compute(vec, parent_idx, idx+1, weight);

                    pt_data[sorted_memo[idx].second].second = pt_data[sorted_memo[idx+1].second].second;

                    if(pt_data[sorted_memo[idx].second].second){
                        sum_table[sorted_memo[idx].second] = (2*next_cost)%mod;
                    }
                    else{
                        sum_table[sorted_memo[idx].second] = 1;
                    }
                }

                else{
                    pt_data[sorted_memo[idx].second].second = false;
                    sum_table[sorted_memo[idx].second] = 1;
                }

                return sum_table[sorted_memo[idx].second];

            }
            else{
                pt_data[sorted_memo[idx].second].second = true;

                ll cost = weight + (vec_idx.second - vec_idx.first), child_cost;
                ll new_weight = weight + (vec_idx.second - vec_idx.first);
                ll child_idx = stdrd_bin_search(cost, vec[sorted_memo[idx].second], sorted_memo, 0, sorted_memo.size() - 1);

                if(child_idx != -1){
                    child_cost = sum_table_compute(vec, sorted_memo[idx].second, child_idx, new_weight);
                    if(child_cost)
                        sum_table[sorted_memo[idx].second] = child_cost%mod;
                    else
                        sum_table[sorted_memo[idx].second] = 1;
                }

                else{
                    sum_table[sorted_memo[idx].second] = 1;
                }

                if(sorted_memo[idx + 1].first == weight){

                    sum_table[sorted_memo[idx].second] = (sum_table[sorted_memo[idx].second] + (sum_table_compute(vec, parent_idx, idx+1, weight)))%mod;

                }

                return sum_table[sorted_memo[idx].second];
            }
        }

    }

}

// void solve(vector<pair<ll, ll> > vec, int idx, ll weight){

//     if(pt_data.find(idx) != pt_data.end()){
//         return ;
//     }

//     ll ans = 0;

//     int new_idx = bin_search_min(vec[idx], vec, idx+1, vec.size() - 1, weight);

//     if(!weight && new_idx == -1){

//         sum_table[idx] = 1;

//         pt_data[idx].first = 0;

//         if(vec[idx].first == vec[idx].second){
//             pt_data[idx].second = false;
//         }

//         else{
//             pt_data[idx].second = true;
//         }

//         return ;
//     }

//     else if(weight && new_idx == -1){

//         return ;
//     }

//     auto sz = sum_table.lower_bound(idx);
//     ll upl = vec.size(), ans = INF;

//     // getting the successor of the key

//     if(sz->second){
//         ans = sz->second - (vec[idx].second - vec[idx].first);
//         upl = sz->first; // We know minimum of all elements from sz->first......n, hence checking from
//                          // new_idx to sz->first only
//     }

//     while(new_idx < idx){

//         new_idx--;
//     }

// }

ll findMinimum(vector<pair<ll, ll> > vec, int idx){

    if(memo.find(idx) != memo.end()){
        return memo[idx];
    }

    pair<ll, ll> vec_idx = vec[idx];

    int new_idx = bin_search(vec_idx, vec, idx+1, (vec.size())-1);

    if(new_idx == -1){
        memo[idx] = vec_idx.first;
        dp[idx] = vec_idx.first;
        return vec_idx.first;
    }

    ll upl = vec.size(), ans = INF, temp, tmp, prevMin = INF;

    for(int i = new_idx; i < upl; i++){
        if(dp.find(i) == dp.end()){
            temp = findMinimum(vec, i);
            tmp = temp - (vec_idx.second - vec_idx.first);
            if(ans > tmp){
                ans = tmp;
                dp[i] = temp;
                prevMin = dp[i];
            }
            else{
                dp[i] = prevMin;
            }
        }
        else{
            ans = min(ans, dp[i] - (vec_idx.second - vec_idx.first));
            break;
        }
    }

    memo[idx] = ans;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    ll in, out, min_big_engh = INF, finAns = 0;

    cin >> n;

    vector<pair<ll, ll> > arr(n);

    for(int i = 0; i < n; i++){
        cin >> out >> in;

        arr[i].first = in;
        arr[i].second = out;

    }

    sort(arr.begin(), arr.end());

    for(int i = 0; i < n; i++){

        ll temp = findMinimum(arr, i);

        if(min_big_engh > temp){
            min_big_engh = temp;
        }
    }

    for(int i = 0; i < n; i++){
        sorted_memo.push_back(make_pair(memo[i], i));
    }

    sort(sorted_memo.begin(), sorted_memo.end());

    // cout << "min_big_engh is " << min_big_engh << endl;
    // for(int i = 0; i < n; i++){
    //     cout << sorted_memo[i].first << " " << sorted_memo[i].second << endl;
    // }

    for(int i = 0; i < n; i++){
        if(sum_table.find(i) == sum_table.end()){
            int i_child = stdrd_bin_search(min_big_engh + (arr[i].second - arr[i].first), arr[i], sorted_memo, 0, arr.size() - 1);
            if(i_child != -1){
                ll sum_i = sum_table_compute(arr, i, i_child, min_big_engh+(arr[i].second - arr[i].first));
                if(arr[i].first != arr[i].second)
                    finAns = (finAns + sum_i)%mod;
                else{
                    if(pt_data[sorted_memo[i_child].second].second){
                        finAns = (finAns + 2*sum_i)%mod;
                    }
                    else{
                        finAns = (finAns + 1)%mod;
                    }
                }
            }

            else{
                if(min_big_engh == arr[i].first){
                    finAns = (finAns + 1)%mod;
                }
            }
        }
    }

    // cout << "iteration count is " << itCount << endl;
    cout << finAns << endl;

    return 0;
}