/**
 * author: Fidelity
 * date: Jul 22 2019
 * cur fav: https://www.youtube.com/watch?v=hjfzFVw2Zjo :/
**/

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) (x).begin(), (x).end()
#define fap(x) cout << " -- " << #x << ": " << (x) << "\n"
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;
const long double EPS = 1e-9;

const ll MOD = 1e9 + 7;
const ll MOD2 = MOD*MOD;
const int N = 2e5 + 7;
pll dp[N];

namespace pu {
    // point update, range query maximum
    // const int N = 100000+7;
    ll tr[4*N];

    void build() {
        memset(tr, 0, sizeof tr);
    }

    // adds x in point p
    void update(int at, int l, int r, int p, ll x) {
        if(l == r) {
            tr[at] += x;
            return ;
        }

        int lc = at+at, rc = lc+1, mid = (l+r)/2;
        if(p <= mid) update(lc, l, mid, p, x);
        else update(rc, mid+1, r, p, x);
        tr[at] = max(tr[lc], tr[rc]);
    }

    // returns the maximum in lo-hi range
    ll query(int at, int l, int r, int lo, int hi) {
        if(l > hi or r < lo) return 0;	// minimum value, change accordingly
        if(l >= lo and r <= hi) return tr[at];

        int lc = at+at, rc = lc+1, mid = (l+r)/2;
        return max(query(lc, l, mid, lo, hi), query(rc, mid+1, r, lo, hi));
    }
};

// mini in a range with lazy propagation.
struct SegmentTree
{
	typedef pll T;
	#define MAX 200007
	#define lc (at<<1)
	#define rc ((at<<1)|1)

	T Tree[4*MAX];

	SegmentTree() { }

	void build(int at, int l, int r)
	{
		if(l==r)
		{
			Tree[at]=T(0, 1); // Tree[at] = in[l]; input values
			return;
		}
		int mid=(l+r)/2;
		build(lc,l,mid);
		build(rc,mid+1,r);

		if(Tree[lc].first == Tree[rc].first) Tree[at] = T(Tree[lc].first, Tree[lc].second+Tree[rc].second);
		else Tree[at] = min(Tree[lc], Tree[rc]);
	}

	// Range update
	void update2(int at, int l, int r, int p, T val)
	{
		if(l == r)
		{
			Tree[at]=val;
			return;
		}

		int mid=(l+r)/2;
		if(p <= mid) update2(lc,l,mid,p,val);
		else update2(rc,mid+1,r,p,val);

		if(Tree[lc].first == Tree[rc].first) Tree[at] = T(Tree[lc].first, (Tree[lc].second+Tree[rc].second));
		else Tree[at] = min(Tree[lc], Tree[rc]);
		if(Tree[at].second >= MOD2) Tree[at].second -= MOD2;
	}
	// Range query
	T query(int at, int l, int r, int x, int y)
	{
		if(x>r || y<l) return T(INF, INF);
		if(x<=l && r<=y) return Tree[at];

		int mid=(l+r)/2;
		auto q1 = query(lc,l,mid,x,y);
		auto q2 = query(rc,mid+1,r,x,y);
		T ret;
		if(q1.first == q2.first) return ret = T(q1.first, (q1.ss + q2.ss));
        else ret = min(q1, q2);
        if(ret.second >= MOD2) ret.second -= MOD2;
        return ret;
	}
} seg;

#define in second
#define out first

int main() {
    FastIO;

    // ..

    int n;
    cin >> n;
    vector<pll> v(n+1);
    v[0] = pll(-INF, -INF);
    for(int i=1; i<=n; ++i) cin >> v[i].first >> v[i].second;

    sort(all(v));

    seg.build(1, 1, n);
    pu::build();

    for(int i=1; i<=n; ++i) {
        seg.update2(1, 1, n, i, pll(v[i].in - v[i].out, 1));
        pu::update(1, 1, n, i, v[i].in);
    }

    for(int i=1; i<=n; ++i) {
        dp[i] = pll(v[i].in, 1);

        int rpos = upper_bound(all(v), pll(v[i].in, INF)) - v.begin();
        --rpos;

        int lo = 1, hi = rpos;
        while(lo < hi) {
            int _mid = (lo + hi) / 2;
            ll mval = pu::query(1, 1, n, _mid+1, rpos);
            if(v[_mid].out <= mval) lo = _mid + 1;
            else hi = _mid;
        }
        int lpos = hi;

        pll temp = seg.query(1, 1, n, lpos, rpos);
        temp.ff += v[i].in;
        if(temp.ff == dp[i].ff) dp[i].ss += temp.ss;
        else dp[i] = min(dp[i], temp);

        dp[i].ss %= MOD;
        seg.update2(1, 1, n, i, pll(dp[i].first-v[i].out, dp[i].second));
    }

    pll mini(INF, 0);
    for(int i=1; i<=n; ++i) {
        ll mval = pu::query(1, 1, n, i+1, n);
        if(v[i].out <= mval) continue;

        if(dp[i].first == mini.first) {
            mini.ss += dp[i].ss;
            if(mini.ss >= MOD2) mini.ss -= MOD2;
        }
        else mini = min(mini, dp[i]);
    }

    ll res = mini.ss % MOD;
    cout << res << "\n";

    return 0;
}

/**

2 1
3 2
4 1
4 2
4 2
5 4
6 4

**/


#include "bits/stdc++.h"

using namespace std;

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define vi                                        vector<int>
#define vpii                                      vector< pii >

#define all(v)                                    v.begin(),v.end()
#define sz(re)                                    (int)re.size()
#define mset(a,f)                                 memset(a,f,sizeof(a))
#define M                                         1000000007
#define Think_Twice_Code_Once                     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

bool J27 = 1;
#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(!J27)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7;
const long long INF = LLONG_MAX;
const int inf = INT_MAX;

int n, Q;
int arr[N+2];
map < int, int > mp;

void solve()
{
      cin >> n;
      vpii vec(n);
      lop(i,0,n) cin >> vec[i].ss >> vec[i].ff;

      sort( all(vec) );

      int minspace = INF;

      lop(i,0,n)
      {
            if( vec[i].ff > minspace ) break;
            else
            {
                  pii p = { vec[i].ss, 0 };
                  auto id = lower_bound( vec.begin(), vec.end(), p) - vec.begin();
                  if( id != n and id > i )
                  {
                        int val = vec[i].ff + vec[id].ff - vec[i].ss;
                        minspace = min( minspace , val);
                  }
            }
      }

      mp.clear();
      int mx = -1;

      rlop(i, n-1, 0)
      {
            if( mx < vec[i].ss )
            {
                  mx = max( mx, vec[i].ff );
                  mp[ vec[i].ff ]++;
                  mp[ vec[i].ff ] %= M;
            }
            else
            {
                  if( mp.find( vec[i].ss ) != mp.end() )
                  {
                        mp[ vec[i].ff ] += mp[ vec[i].ss ];
                        mp[ vec[i].ff ] %= M;
                  }
            }
      }

      int ans = 0;
      lop(i,0,n)
      {

            if( vec[i].ff > minspace ) break;
            else
            {
                  pii p = { vec[i].ss, 0 };
                  auto id = lower_bound( vec.begin(), vec.end(), p) - vec.begin();
                  if( id != n and id > i )
                  {
                        int val = vec[i].ff + vec[id].ff - vec[i].ss;
                        ans += mp[ vec[i].ss ];
                        ans %= M;
                  }
            }

      }

      cout << ans << endl;
      // bug( minspace );

}

int32_t main()
{

      J27 = 1;
      Think_Twice_Code_Once;
      INP();
      int t = 1;
      //cin >> t;
      while(t--) solve();

}

inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //


#include "bits/stdc++.h"

using namespace std;

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define vi                                        vector<int>
#define vpii                                      vector< pii >

#define all(v)                                    v.begin(),v.end()
#define sz(re)                                    (int)re.size()
#define mset(a,f)                                 memset(a,f,sizeof(a))
#define M                                         1000000007
#define Think_Twice_Code_Once                     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

bool J27 = 1;
#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(!J27)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7;
const long long INF = LLONG_MAX;
const int inf = INT_MAX;

int n, Q;
int arr[N+2];
map < int, int > mp;

void solve()
{
      cin >> n;
      vpii vec(n);
      lop(i,0,n) cin >> vec[i].ss >> vec[i].ff;

      sort( all(vec) );

      int minspace = INF;

      lop(i,0,n)
      {
            if( vec[i].ff > minspace ) break;
            else
            {
                  pii p = { vec[i].ss, 0 };
                  auto id = lower_bound( vec.begin(), vec.end(), p) - vec.begin();
                  if( id != n and id > i )
                  {
                        int val = vec[i].ff + vec[id].ff - vec[i].ss;
                        minspace = min( minspace , val);
                  }
            }
      }

      mp.clear();
      int mx = -1;

      rlop(i, n-1, 0)
      {
            if( mx < vec[i].ss )
            {
                  mx = max( mx, vec[i].ff );
                  mp[ vec[i].ff ]++;
                  mp[ vec[i].ff ] %= M;
            }
            else
            {
                  if( mp.find( vec[i].ss ) != mp.end() )
                  {
                        mp[ vec[i].ff ] += mp[ vec[i].ss ];
                        mp[ vec[i].ff ] %= M;
                  }
            }
      }

      int ans = 0;
      lop(i,0,n)
      {

            if( vec[i].ff > minspace ) break;
            else
            {
                  pii p = { vec[i].ss, 0 };
                  auto id = lower_bound( vec.begin(), vec.end(), p) - vec.begin();
                  if( id != n and id > i )
                  {
                        int val = vec[i].ff + vec[id].ff - vec[i].ss;
                        ans += mp[ vec[i].ss ];
                        ans %= M;
                  }
            }

      }

      if( minspace == INF ) ans = n;
      cout << ans << endl;
      // bug( minspace );

}

int32_t main()
{

      J27 = 1;
      Think_Twice_Code_Once;
      INP();
      int t = 1;
      //cin >> t;
      while(t--) solve();

}

inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //


#include "bits/stdc++.h"

using namespace std;

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define vi                                        vector<int>
#define vpii                                      vector< pii >

#define all(v)                                    v.begin(),v.end()
#define sz(re)                                    (int)re.size()
#define mset(a,f)                                 memset(a,f,sizeof(a))
#define M                                         1000000007
#define Think_Twice_Code_Once                     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

bool J27 = 1;
#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(!J27)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7;
const long long INF = LLONG_MAX;
const int inf = INT_MAX;

int n, Q;
int arr[N+2];
map < int, int > mp;

void solve()
{
      cin >> n;
      vpii vec(n);
      lop(i,0,n) cin >> vec[i].ss >> vec[i].ff;

      sort( all(vec) );

      int minspace = INF;

      lop(i,0,n)
      {
            if( vec[i].ff > minspace ) break;
            else
            {
                  pii p = { vec[i].ss, 0 };
                  auto id = lower_bound( vec.begin(), vec.end(), p) - vec.begin();
                  if( id != n and id > i )
                  {
                        int val = vec[i].ff + vec[id].ff - vec[i].ss;
                        minspace = min( minspace , val);
                  }
            }
      }

      mp.clear();
      int mx = -1;

      rlop(i, n-1, 0)
      {
            if( mx < vec[i].ss )
            {
                  mx = max( mx, vec[i].ff );
                  mp[ vec[i].ff ]++;
                  mp[ vec[i].ff ] %= M;
            }
            else
            {
                  if( mp.find( vec[i].ss ) != mp.end() )
                  {
                        mp[ vec[i].ff ] += mp[ vec[i].ss ];
                        mp[ vec[i].ff ] %= M;
                  }
            }
      }

      int ans = 0;
      minspace = vec[0].ff;
      ans  = mp[ minspace ];

      // lop(i,0,n)
      // {

      //       if( vec[i].ff > minspace ) break;
      //       else
      //       {
      //              if
      //              ans += mp[ vec[i].ff ];

      //             // pii p = { vec[i].ss, 0 };
      //             // auto id = lower_bound( vec.begin(), vec.end(), p) - vec.begin();
      //             // if( id != n and id > i )
      //             // {
      //             //       if( vec[i].ff < minspace ) ans += mp[ vec[i].ss ];
      //             //       else ans += mp[ vec[i].ff ];
      //             //       ans %= M;
      //             // }
      //       }
      // }

      if( minspace == INF ) ans = n;
      cout << ans << endl;
      return;
      bug( minspace );
      for( auto i: mp ) bug(i.ff, i.ss);

}

int32_t main()
{

      J27 = 1;
      Think_Twice_Code_Once;
      INP();
      int t = 1;
      //cin >> t;
      while(t--) solve();

}

inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

pii arr[N+2];
int n, Q;

// Segment Tree

class Segtree{
public:

     // for '0' index  queries

     int sz;
     pii *segt;
     pii *from;

     Segtree(int x, pii *array)
     {
        sz = x;
        segt = new pii[4*sz];
        from = array;
        build();
     }

     pii ff(pii a,pii b)
     {
          if( a.ff < b.ff ) return a;
          if( a.ff > b.ff ) return b;
          a.ss += b.ss;
          a.ss %= M;
          return a;
     }

     pii queryUtil(int l, int r, int i, int L, int R)
     {
          if( r < L or R < l ) return {inf,0};     // change here
          if( L <= l && r <= R)   return segt[i];

          int mid = l + (r-l)/2;
          pii a = queryUtil(l    , mid, 2*i + 1, L, R);
          pii b = queryUtil(mid+1, r  , 2*i + 2, L, R);

          return ff(a,b);
     }

     pii upd(int i)
     {

         pii a = segt[ 2*i + 1 ];
         pii b = segt[ 2*i + 2 ];

         return ff(a,b);
     }

     void build()
     {
          buildUtil(0, sz-1, 0);                  // l, r, i
     }

     pii query(int L, int R)
     {
          return queryUtil(0, sz-1, 0, L, R);     // l, r, i, L, R
     }

     void update(int idx , pii val)
     {
          updateUtil(0, sz-1, 0, idx, val);       // l, r , i, idx , val
     }

     void buildUtil(int l, int r , int i)
     {

          if( l == r )
          {
               segt[i] = from[r];
               return;
          }
          int mid = l + (r-l)/2;
          buildUtil(l,   mid, 2*i + 1 );
          buildUtil(mid+1, r, 2*i + 2 );

          segt[i] = upd(i);

     }

     void updateUtil( int l, int r, int i, int idx, pii val)
     {

          if( l > idx || r < idx ) return ;

          if( l == r and l == idx )
          {
               segt[i] = val;
               from[idx] = val;
               return;
          }

          int mid = l + (r-l)/2;
          updateUtil(l, mid, i*2 + 1, idx, val);
          updateUtil(mid+1, r, i*2 + 2, idx, val);

          segt[i] = upd(i);
     }

};

int getid(vector< pii > &vec, int st, int val)
{
      int  en = (int)vec.size() - 1, ans = -1;
      while( st <= en )
      {
            int mid = (st+en)/2;
            if( vec[mid].ff >= val ) ans = mid, en = --mid;
            else st = ++mid;
      }
      return ans;
}

void solve()
{
      cin >> n;
      vector< pii > vec(n);
      lop(i,0,n) cin >> vec[i].ss >> vec[i].ff;
      sort( all( vec ) );

      Segtree mafia(n, arr);
      int ans = 0;
      rlop(i,n-1,0)
      {
            int x = getid(vec, i+1, vec[i].ss);
            if( x == -1 )
            {
                  mafia.update(i, {vec[i].ff, 1} );
            }
            else
            {
                  pii r = mafia.query(x, n-1);
                  mafia.update(i, {r.ff - (vec[i].ss - vec[i].ff), r.ss});
            }
      }
      pii r = mafia.query(0,n-1);
      cout << r.ss << endl;

}

int32_t main()
{

      ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);
      INP();
      int t = 1;
      //cin >> t;
      while(t--) solve();

}

inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //


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

const int N = 220000;
const int MOD = 1e9 + 7;
const long long INF = 1LL << 60;

struct Node {
	long long Min;
	int cnt;
	Node(long long Min = 0, int cnt = 0) : Min(Min), cnt(cnt) {}
} node[1 << 20];

inline void update(int id, const Node &val) {
	node[id] = val;
}

inline Node merge(const Node &u, const Node &v) {
	Node ret;
	ret.Min = min(u.Min, v.Min);
	ret.cnt = 0;
	if (ret.Min == u.Min) ret.cnt += u.cnt;
	if (ret.Min == v.Min) (ret.cnt += v.cnt) >= MOD && (ret.cnt -= MOD);
	return ret;
}

inline void up(int id) {
	node[id] = merge(node[id + id], node[id + id + 1]);
}

inline void modify(int id, int st, int en, int pos, const Node &val) {
	if (pos <= st && en <= pos) {
		update(id, val);
		return;
	}
	int mid = st + en >> 1;
	if (pos <= mid) modify(id + id, st, mid, pos, val);
	if (pos > mid) modify(id + id + 1, mid + 1, en, pos, val);
	up(id);
}

inline Node query(int id, int st, int en, int l, int r) {
	if (l > r) return Node(INF, 0);
	if (l <= st && en <= r) return node[id];
	int mid = st + en >> 1;
	Node ret(INF, 0);
	if (l <= mid) ret = merge(ret, query(id + id, st, mid, l, r));
	if (r > mid) ret = merge(ret, query(id + id + 1, mid + 1, en, l, r));
	return ret;
}

pair<int, int> a[N];
int Max_in[N];

Node dp[N];

int main() {

	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) {
		auto it = lower_bound(a + 1, a + n + 1, make_pair(a[i].second + 1, 0));
		int r = it - a - 1;
		int l = lower_bound(a + 1, a + n + 1, make_pair(a[Max_in[r]].second + 1, 0)) - a;
		if (a[Max_in[i - 1]].second < a[i].second) Max_in[i] = i;
		else Max_in[i] = Max_in[i - 1];
		auto ret = query(1, 1, n, l, r);
		if (ret.Min == INF) ret = Node(0, 1);
		ret.Min += a[i].second - a[i].first;
		modify(1, 1, n, i, ret);
		dp[i] = ret;
		dp[i].Min += a[i].first;
	}
	int Max_in_val = a[Max_in[n]].second;
	Node ans(INF, 0);
	for (int i = 1; i <= n; i++) if (a[i].first > Max_in_val) ans = merge(ans, dp[i]);
	cout << ans.cnt << "\n";

	return 0;
}


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

const int N = 220000;
const int MOD = 1e9 + 7;
const long long INF = 1LL << 60;

struct Node {
	long long Min;
	int cnt;
	Node(long long Min = 0, int cnt = 0) : Min(Min), cnt(cnt) {}
} node[1 << 20];

inline void update(int id, const Node &val) {
	node[id] = val;
}

inline Node merge(const Node &u, const Node &v) {
	Node ret;
	ret.Min = min(u.Min, v.Min);
	ret.cnt = 0;
	if (ret.Min == u.Min) ret.cnt += u.cnt;
	if (ret.Min == v.Min) (ret.cnt += v.cnt) >= MOD && (ret.cnt -= MOD);
	return ret;
}

inline void up(int id) {
	node[id] = merge(node[id + id], node[id + id + 1]);
}

inline void modify(int id, int st, int en, int pos, const Node &val) {
	if (pos <= st && en <= pos) {
		update(id, val);
		return;
	}
	int mid = st + en >> 1;
	if (pos <= mid) modify(id + id, st, mid, pos, val);
	if (pos > mid) modify(id + id + 1, mid + 1, en, pos, val);
	up(id);
}

inline Node query(int id, int st, int en, int l, int r) {
	if (l > r) return Node(INF, 0);
	if (l <= st && en <= r) return node[id];
	int mid = st + en >> 1;
	Node ret(INF, 0);
	if (l <= mid) ret = merge(ret, query(id + id, st, mid, l, r));
	if (r > mid) ret = merge(ret, query(id + id + 1, mid + 1, en, l, r));
	return ret;
}

pair<int, int> a[N];
int Max_in[N];

Node dp[N];

int main() {

	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) {
		auto it = lower_bound(a + 1, a + n + 1, make_pair(a[i].second + 1, 0));
		int r = it - a - 1;
		int l = lower_bound(a + 1, a + n + 1, make_pair(Max_in[r] + 1, 0)) - a;
		if (a[Max_in[i - 1]].second < a[i].second) Max_in[i] = i;
		else Max_in[i] = Max_in[i - 1];
		auto ret = query(1, 1, n, l, r);
		if (ret.Min == INF) ret = Node(0, 1);
		ret.Min += a[i].second - a[i].first;
		modify(1, 1, n, i, ret);
		dp[i] = ret;
		dp[i].Min += a[i].first;
	}
	int Max_in_val = a[Max_in[n]].second;
	Node ans(INF, 0);
	for (int i = 1; i <= n; i++) if (a[i].first > Max_in_val) ans = merge(ans, dp[i]);
	cout << ans.cnt << "\n";

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <list>
#include <queue>
#include <stack>
#include <utility>
#include <cmath>
#include <limits.h>
#define rep(i,a) for(i=0;i<a;i++)
#define lp(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
typedef long long ll;
typedef unsigned long ul;
using namespace std;

const ll MOD = 1000000007;

ll GCD(ll a,ll b){
    if(b==0)
        return a;
    return GCD(b,a%b);
}

void func(vector<pair<ll,ll>> &dp, vector< pair<ll,ll>> &arr, vector<ll> &arr1, ll i){
    if(i>=arr.size()){
        return;
    }
    if(dp[i].first!=-1){
        return;
    }
    auto ptr = lower_bound(arr1.begin(),arr1.end(),arr[i].second);
    if(ptr==arr1.end()){
        func(dp,arr,arr1,i+1);
        if(i+1<arr1.size()){
            if(dp[i+1].second==arr1[i]){
                dp[i]={(dp[i+1].first+1)%MOD,arr1[i]};
            }else if(dp[i+1].second<arr1[i]){
                dp[i]=dp[i+1];
            }else {
                dp[i] = {1,arr1[i]};
            }
        }else {
            dp[i] = {1, arr1[i]};
        }
        return;
    }
    ll index = ptr-arr1.begin();
    func(dp,arr,arr1,index);
    func(dp,arr,arr1,i+1);
    ll temp1 = dp[index].second-(arr[i].second-arr[i].first);
    ll temp2 = dp[index].first;
    ll temp3 = dp[i+1].second;
    ll temp4 = dp[i+1].first;
    if(temp1<temp3)
        dp[i] = {temp2,temp1};
    else if(temp1==temp3)
        dp[i] = {(temp2+temp4)%MOD,temp1};
    else
        dp[i] = {temp4,temp3};
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //begin here
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j;
    cin>>n;
    vector< pair<ll,ll> > arr(n);
    vector<ll> arr1(n);
    for(i=0;i<n;i++){
        cin>>arr[i].second>>arr[i].first;
    }
    sort(arr.begin(),arr.end());
    for(i=0;i<n;i++){
        arr1[i] = arr[i].first;
    }
//    auto ptr = lower_bound(arr1.begin(),arr1.end(),2ll);
//    cout<<ptr-arr1.begin();
    vector< pair<ll,ll> > dp(n,{-1,-1});// {no of ways, curr vol}
    func(dp,arr,arr1,0);
    cout<<dp[0].first<<"\n";
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <list>
#include <queue>
#include <stack>
#include <utility>
#include <cmath>
#include <limits.h>
#define rep(i,a) for(i=0;i<a;i++)
#define lp(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
typedef long long ll;
typedef unsigned long ul;
using namespace std;

ll GCD(ll a,ll b){
    if(b==0)
        return a;
    return GCD(b,a%b);
}

void func(vector<pair<ll,ll>> &dp, vector< pair<ll,ll>> &arr, vector<ll> &arr1, ll i){
    if(i>=arr.size()){
        return;
    }
    if(dp[i].first!=-1){
        return;
    }
    auto ptr = lower_bound(arr1.begin(),arr1.end(),arr[i].second);
    if(ptr==arr1.end()){
        func(dp,arr,arr1,i+1);
        if(i+1<arr1.size()){
            if(dp[i+1].second==arr1[i]){
                dp[i]={dp[i+1].first+1,arr1[i]};
            }else if(dp[i+1].second<arr1[i]){
                dp[i]=dp[i+1];
            }else {
                dp[i] = {1,arr1[i]};
            }
        }else {
            dp[i] = {1, arr1[i]};
        }
        return;
    }
    ll index = ptr-arr1.begin();
    func(dp,arr,arr1,index);
    func(dp,arr,arr1,i+1);
    ll temp1 = dp[index].second-arr1[i];
    ll temp2 = dp[index].first;
    ll temp3 = dp[i+1].second;
    ll temp4 = dp[i+1].first;
    if(temp1<temp3)
        dp[i] = {temp2,temp1};
    else if(temp1==temp3)
        dp[i] = {temp2+temp4,temp1};
    else
        dp[i] = {temp4,temp3};
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //begin here
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j;
    cin>>n;
    vector< pair<ll,ll> > arr(n);
    vector<ll> arr1(n);
    for(i=0;i<n;i++){
        cin>>arr[i].second>>arr[i].first;
    }
    sort(arr.begin(),arr.end());
    for(i=0;i<n;i++){
        arr1[i] = arr[i].first;
    }
//    auto ptr = lower_bound(arr1.begin(),arr1.end(),2ll);
//    cout<<ptr-arr1.begin();
    vector< pair<ll,ll> > dp(n,{-1,-1});// {no of ways, curr vol}
    func(dp,arr,arr1,0);
    cout<<dp[0].first<<"\n";
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <list>
#include <queue>
#include <stack>
#include <utility>
#include <cmath>
#include <limits.h>
#define rep(i,a) for(i=0;i<a;i++)
#define lp(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
typedef long long ll;
typedef unsigned long ul;
using namespace std;

ll GCD(ll a,ll b){
    if(b==0)
        return a;
    return GCD(b,a%b);
}

void func(vector<pair<ll,ll>> &dp, vector< pair<ll,ll>> &arr, vector<ll> &arr1, ll i){
    if(i>=arr.size()){
        return;
    }
    if(dp[i].first!=-1){
        return;
    }
    auto ptr = lower_bound(arr1.begin(),arr1.end(),arr[i].second);
    if(ptr==arr1.end()){
        func(dp,arr,arr1,i+1);
        if(i+1<arr1.size()){
            if(dp[i+1].second==arr1[i]){
                dp[i]={dp[i+1].first+1,arr1[i]};
            }else if(dp[i+1].second<arr1[i]){
                dp[i]=dp[i+1];
            }else {
                dp[i] = {1,arr1[i]};
            }
        }else {
            dp[i] = {1, arr1[i]};
        }
        return;
    }
    ll index = ptr-arr1.begin();
    func(dp,arr,arr1,index);
    func(dp,arr,arr1,i+1);
    ll temp1 = dp[index].second-(arr[i].second-arr[i].first);
    ll temp2 = dp[index].first;
    ll temp3 = dp[i+1].second;
    ll temp4 = dp[i+1].first;
    if(temp1<temp3)
        dp[i] = {temp2,temp1};
    else if(temp1==temp3)
        dp[i] = {temp2+temp4,temp1};
    else
        dp[i] = {temp4,temp3};
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //begin here
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j;
    cin>>n;
    vector< pair<ll,ll> > arr(n);
    vector<ll> arr1(n);
    for(i=0;i<n;i++){
        cin>>arr[i].second>>arr[i].first;
    }
    sort(arr.begin(),arr.end());
    for(i=0;i<n;i++){
        arr1[i] = arr[i].first;
    }
//    auto ptr = lower_bound(arr1.begin(),arr1.end(),2ll);
//    cout<<ptr-arr1.begin();
    vector< pair<ll,ll> > dp(n,{-1,-1});// {no of ways, curr vol}
    func(dp,arr,arr1,0);
    cout<<dp[0].first<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define M 200005
#define MOD 1000000007
typedef pair<int, int> pii;

pii ara[M];
int dp[M], cum[M];
int res[M], ans[M];
bool ehhe[M];

int getAghe(int i)
{
    int j = upper_bound(ara+1, ara+i, make_pair(ara[i].second, MOD))-ara-1;
    return j;
}

int main()
{
    int n;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) scanf("%d %d", &ara[i].first, &ara[i].second);
    sort(ara+1, ara+n+1);

    for(int i = 1; i <= n; i++)
    {
        dp[i] = ara[i].first-ara[i].second+cum[getAghe(i)];
        cum[i] = max(cum[i-1], dp[i]);
    }

    res[0] = ans[0] = 1;
    for(int i = 1; i <= n; i++)
    {
        ans[i] = res[getAghe(i)];

        if(dp[i] < cum[i]) res[i] = res[i-1];
        else res[i] = ans[i];

        if(dp[i] == cum[i-1]) res[i] += res[i-1], res[i] %= MOD;
    }

    //for(int i = 1; i <= n; i++) printf("%d: %d %d %d %d\n", i, dp[i], cum[i], ans[i], res[i]);

    vector<int> vec;
    int curmx = 0;

    for(int i = n; i; i--)
    {
        if(ehhe[i]) break;
        int j = getAghe(i);
        ehhe[j] = true;

        if(ara[i].first-dp[i] > curmx)
        {
            curmx = ara[i].first-dp[i];
            vec.clear();
            vec.push_back(i);
        }
        else if(ara[i].first-dp[i] == curmx) vec.push_back(i);
    }

    int cutu = 0;
    for(int idx: vec) cutu += ans[idx], cutu %= MOD;

    printf("%d\n", cutu);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define M 200005
#define MOD 1000000007
typedef pair<int, int> pii;

pii ara[M];
int dp[M], cum[M];
int res[M], ans[M];
bool ehhe[M];

int getAghe(int i)
{
    int j = upper_bound(ara+1, ara+i, make_pair(ara[i].second, MOD))-ara-1;
    return j;
}

int main()
{
    int n;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) scanf("%d %d", &ara[i].first, &ara[i].second);
    sort(ara+1, ara+n+1);

    for(int i = 1; i <= n; i++)
    {
        dp[i] = ara[i].first-ara[i].second+cum[getAghe(i)];
        cum[i] = max(cum[i-1], dp[i]);
    }

    res[0] = ans[0] = 1;
    for(int i = 1; i <= n; i++)
    {
        ans[i] = res[getAghe(i)];

        if(dp[i] < cum[i]) res[i] = res[i-1];
        else res[i] = ans[i];

        if(dp[i] == cum[i-1]) res[i] += res[i-1], res[i] %= MOD;
    }

    //for(int i = 1; i <= n; i++) printf("%d: %d %d %d %d\n", i, dp[i], cum[i], ans[i], res[i]);

    vector<int> vec;
    int curmx = MOD;

    for(int i = n; i; i--)
    {
        if(ehhe[i]) break;
        int j = getAghe(i);
        ehhe[j] = true;

        if(ara[i].first-dp[i] < curmx)
        {
            curmx = ara[i].first-dp[i];
            vec.clear();
            vec.push_back(i);
        }
        else if(ara[i].first-dp[i] == curmx) vec.push_back(i);
    }

    int cutu = 0;
    for(int idx: vec) cutu += ans[idx], cutu %= MOD;

    printf("%d\n", cutu);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define M 200005
#define MOD 1000000007
typedef pair<int, int> pii;

pii ara[M];
int dp[M], cum[M];
int res[M], ans[M];

int getAghe(int i)
{
    int j = upper_bound(ara+1, ara+i, make_pair(ara[i].second, MOD))-ara-1;
    return j;
}

int main()
{
    int n;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) scanf("%d %d", &ara[i].first, &ara[i].second);
    sort(ara+1, ara+n+1);

    for(int i = 1; i <= n; i++)
    {
        dp[i] = ara[i].first-ara[i].second+cum[getAghe(i)];
        cum[i] = max(cum[i-1], dp[i]);
    }

    res[0] = ans[0] = 1;
    for(int i = 1; i <= n; i++)
    {
        ans[i] = res[getAghe(i)];

        if(dp[i] < cum[i]) res[i] = res[i-1];
        else res[i] = ans[i];

        if(dp[i] == cum[i-1]) res[i] += res[i-1], res[i] %= MOD;
    }

    vector<int> vec;
    int curmx = 0;

    for(int i = 1; i <= n; i++)
    {
        if(dp[i]-ara[i].first+ara[i].second > curmx)
        {
            curmx = dp[i]-ara[i].first+ara[i].second;
            vec.clear();
            vec.push_back(i);
        }
        else if(dp[i]-ara[i].first+ara[i].second == curmx) vec.push_back(i);
    }

    int cutu = 0;
    for(int idx: vec) cutu += ans[idx], cutu %= MOD;

    printf("%d\n", cutu);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define M 200005
#define MOD 1000000007
typedef pair<int, int> pii;

pii ara[M];
int dp[M], cum[M];
int res[M], ans[M];

int getAghe(int i)
{
    int j = upper_bound(ara+1, ara+i, make_pair(ara[i].second, MOD))-ara-1;
    return j;
}

int main()
{
    int n;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) scanf("%d %d", &ara[i].first, &ara[i].second);
    sort(ara+1, ara+n+1);

    for(int i = 1; i <= n; i++)
    {
        dp[i] = ara[i].first-ara[i].second+cum[getAghe(i)];
        cum[i] = max(cum[i-1], dp[i]);
    }

    res[0] = ans[0] = 1;
    for(int i = 1; i <= n; i++)
    {
        ans[i] = res[getAghe(i)];

        if(dp[i] < cum[i]) res[i] = res[i-1];
        else res[i] = ans[i];

        if(dp[i] == cum[i-1]) res[i] += res[i-1], res[i] %= MOD;
    }

    //for(int i = 1; i <= n; i++) printf("%d: %d %d %d %d\n", i, dp[i], cum[i], ans[i], res[i]);

    vector<int> vec;
    int curmx = MOD;

    for(int i = 1; i <= n; i++)
    {
        if(dp[i]-ara[i].first < curmx)
        {
            curmx = dp[i]-ara[i].first;
            vec.clear();
            vec.push_back(i);
        }
        else if(dp[i]-ara[i].first == curmx) vec.push_back(i);
    }

    int cutu = 0;
    for(int idx: vec) cutu += ans[idx], cutu %= MOD;

    printf("%d\n", cutu);

    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
const int mod=1000000007;
//const int mod=998244353;
const int inf=1000000009;
const long long int INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.0000000001;
using namespace std;
pii T[200005];
bool cmp(pii a,pii b)
{
    if(a.st!=b.st)
        return a.st>b.st;
    return a.nd>b.nd;
}
int DP[200005];
struct Node
{
    int s=inf,w=0;
    Node *l=NULL,*p=NULL;
};
void ustaw(int a,int b,int lo,int hi,Node *u,int s,int w)
{
    if(b<=a)
        return;
    if(a==lo&&b==hi)
    {
        if(u->s==s)
            u->w=(u->w+w)%mod;
        else if(u->s>s)
            u->w=w,u->s=s;
        //cout<<lo<<" kij "<<u->s<<" "<<u->w<<endl;
        return;
    }
    int mid=(lo+hi)/2;
    if(u->l==NULL)
        u->l=new Node();
    if(u->p==NULL)
        u->p=new Node();
    ustaw(a,min(b,mid),lo,mid,u->l,s,w);
    ustaw(max(a,mid),b,mid,hi,u->p,s,w);
    if(u->l->s==u->p->s)
        u->w=(u->l->w+u->p->w)%mod,u->s=u->l->s;
    else if(u->l->s<u->p->s)
        u->w=u->l->w,u->s=u->l->s;
    else
        u->w=u->p->w,u->s=u->p->s;
}
pii getwart(int a,int b,int lo,int hi,Node *u)
{
    if(b<=a)
        return mp(inf,0);
    if(a==lo&&b==hi)
        return mp(u->s,u->w);
    int mid=(lo+hi)/2;
    pii L=mp(inf,0),P=mp(inf,0);
    if(u->l!=NULL)
        L=getwart(a,min(b,mid),lo,mid,u->l);
    if(u->p!=NULL)
        P=getwart(max(a,mid),b,mid,hi,u->p);
    if(L.st==P.st)
        return mp(L.st,(L.nd+P.nd)%mod);
    else if(L.st<P.st)
        return L;
    else
        return P;
}
int main()
{
    speed
    int n;
    cin>>n;
    ll suma=1;
    while(suma<inf)
        suma*=2;
    suma*=2;
    suma--;
    for(int i=1; i<=n; i++)
        cin>>T[i].st>>T[i].nd;
    sort(T+1,T+n+1,cmp);
    Node *k=new Node();
    int wynik=0,mini=inf;
    for(int i=1; i<=n; i++)
    {
       // cout<<i<<" def "<<T[i].st<<" "<<T[i].nd<<endl;
        pii x=getwart(T[i].st,suma/2+2,1,suma/2+2,k);
        //cout<<"dziala"<<endl;
        int s;
        if(x.st==inf)
            s=T[i].nd,x.nd=1;
        else
            s=x.st-T[i].st+T[i].nd;
        ustaw(T[i].nd,T[i].nd+1,1,suma/2+2,k,s,x.nd);
        // cout<<"ok"<<endl;
        //cout<<"czesciowka "<<s<<" "<<x.nd<<endl;
        if(i==n||T[i].nd<T[n].st)
        {
           // cout<<i<<endl;
           if(s==mini)
            wynik=(wynik+x.nd)%mod;
            else if(s<mini)
                wynik=x.nd;
        }

    }
    cout<<wynik;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
const int mod=1000000007;
//const int mod=998244353;
const int inf=1000000009;
const long long int INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.0000000001;
using namespace std;
pii T[200005];
bool cmp(pii a,pii b)
{
    if(a.st!=b.st)
        return a.st>b.st;
    return a.nd>b.nd;
}
int DP[200005];
struct Node
{
    int s=inf,w=0;
    Node *l=NULL,*p=NULL;
};
void ustaw(int a,int b,int lo,int hi,Node *u,int s,int w)
{
    if(b<=a)
        return;
    if(a==lo&&b==hi)
    {
        if(u->s==s)
            u->w=(u->w+w)%mod;
        else if(u->s>s)
            u->w=w,u->s=s;
        //cout<<lo<<" kij "<<u->s<<" "<<u->w<<endl;
        return;
    }
    int mid=(lo+hi)/2;
    if(u->l==NULL)
        u->l=new Node();
    if(u->p==NULL)
        u->p=new Node();
    ustaw(a,min(b,mid),lo,mid,u->l,s,w);
    ustaw(max(a,mid),b,mid,hi,u->p,s,w);
    if(u->l->s==u->p->s)
        u->w=(u->l->w+u->p->w)%mod,u->s=u->l->s;
    else if(u->l->s<u->p->s)
        u->w=u->l->w,u->s=u->l->s;
    else
        u->w=u->p->w,u->s=u->p->s;
}
pii getwart(int a,int b,int lo,int hi,Node *u)
{
    if(b<=a)
        return mp(inf,0);
    if(a==lo&&b==hi)
        return mp(u->s,u->w);
    int mid=(lo+hi)/2;
    pii L=mp(inf,0),P=mp(inf,0);
    if(u->l!=NULL)
        L=getwart(a,min(b,mid),lo,mid,u->l);
    if(u->p!=NULL)
        P=getwart(max(a,mid),b,mid,hi,u->p);
    if(L.st==P.st)
        return mp(L.st,(L.nd+P.nd)%mod);
    else if(L.st<P.st)
        return L;
    else
        return P;
}
int main()
{
    speed
    int n;
    cin>>n;
    ll suma=1;
    while(suma<inf)
        suma*=2;
    suma*=2;
    suma--;
    for(int i=1; i<=n; i++)
        cin>>T[i].st>>T[i].nd;
    sort(T+1,T+n+1,cmp);
    Node *k=new Node();
    int wynik=0;
    for(int i=1; i<=n; i++)
    {
       // cout<<i<<" def "<<T[i].st<<" "<<T[i].nd<<endl;
        pii x=getwart(T[i].st,suma/2+2,1,suma/2+2,k);
        //cout<<"dziala"<<endl;
        int s;
        if(x.st==inf)
            s=T[i].nd,x.nd=1;
        else
            s=x.st-T[i].st+T[i].nd;
        ustaw(T[i].nd,T[i].nd+1,1,suma/2+2,k,s,x.nd);
        // cout<<"ok"<<endl;
       // cout<<"czesciowka "<<s<<" "<<x.st<<" "<<x.nd<<endl;
        if(i==n||T[i].nd<T[n].st)
        {
           // cout<<i<<endl;
            wynik=(wynik+x.nd)%mod;
        }

    }
    cout<<wynik;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
const int mod=1000000007;
//const int mod=998244353;
const int inf=1000000009;
const long long int INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.0000000001;
using namespace std;
pii T[200005];
bool cmp(pii a,pii b)
{
    if(a.st!=b.st)
        return a.st>b.st;
    return a.nd>b.nd;
}
int DP[200005];
struct Node
{
    int s=inf,w=1;
    Node *l=NULL,*p=NULL;
};
void ustaw(int a,int b,int lo,int hi,Node *u,int s,int w)
{
    if(b<=a)
        return;
    if(a==lo&&b==hi)
    {
        if(u->s==s)
            u->w=(u->w+w)%mod;
        else if(u->s>s)
            u->w=w;
        return;
    }
    int mid=(lo+hi)/2;
    if(u->l==NULL)
        u->l=new Node();
    if(u->p==NULL)
        u->p=new Node();
        ustaw(a,min(b,mid),lo,mid,u->l,s,w);
        ustaw(max(a,mid),b,mid,hi,u->p,s,w);

     if(u->l->s==u->p->s)
        u->w=(u->l->w+u->p->w)%mod;
    else if(u->l->s<u->p->s)
        u->w=u->l->w;
    else
        u->w=u->p->w;
}
pii getwart(int a,int b,int lo,int hi,Node *u)
{
    if(b<=a)
        return mp(inf,0);
    if(a==lo&&b==hi)
        return mp(u->s,u->w);
    int mid=(lo+hi)/2;
    pii L=mp(inf,0),P=mp(inf,0);
    if(u->l!=NULL)
        L=getwart(a,min(b,mid),lo,mid,u->l);
    if(u->p!=NULL)
        P=getwart(max(a,mid),b,mid,hi,u->p);
    if(L.st==P.st)
        return mp(L.st,(L.st+P.st)%mod);
    else if(L.st<P.st)
        return L;
    else
        return P;
}
int main()
{
    speed
    int n;
    cin>>n;
    ll suma=1;
    while(suma<inf)
        suma*=2;
    suma*=2;
    suma--;
    for(int i=1; i<=n; i++)
        cin>>T[i].st>>T[i].nd;
    sort(T+1,T+n+1,cmp);
    Node *k=new Node();
    int wynik=0;
    for(int i=1; i<=n; i++)
    {
        pii x=getwart(T[i].st,suma/2+2,1,suma/2+2,k);
        //cout<<"dziala"<<endl;
        int s;
        if(x.st==inf)
            s=T[i].nd;
        else
            s=x.st-T[i].st+T[i].nd;
        ustaw(T[i].st,T[i].st+1,1,suma/2+2,k,s,x.nd);
       // cout<<"ok"<<endl;
        if(i==n||T[i].nd<T[n].st)
            wynik=(wynik+x.nd)%mod;
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
const int mod=1000000007;
//const int mod=998244353;
const int inf=1000000009;
const long long int INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.0000000001;
using namespace std;
pii T[200005];
bool cmp(pii a,pii b)
{
    if(a.st!=b.st)
        return a.st>b.st;
    return a.nd>b.nd;
}
int DP[200005];
struct Node
{
    int s=inf,w=0;
    Node *l=NULL,*p=NULL;
};
void ustaw(int a,int b,int lo,int hi,Node *u,int s,int w)
{
    if(b<=a)
        return;
    if(a==lo&&b==hi)
    {
        if(u->s==s)
            u->w=(u->w+w)%mod;
        else if(u->s>s)
            u->w=w,u->s=s;
        //cout<<lo<<" kij "<<u->s<<" "<<u->w<<endl;
        return;
    }
    int mid=(lo+hi)/2;
    if(u->l==NULL)
        u->l=new Node();
    if(u->p==NULL)
        u->p=new Node();
    ustaw(a,min(b,mid),lo,mid,u->l,s,w);
    ustaw(max(a,mid),b,mid,hi,u->p,s,w);
    if(u->l->s==u->p->s)
        u->w=(u->l->w+u->p->w)%mod,u->s=u->l->s;
    else if(u->l->s<u->p->s)
        u->w=u->l->w,u->s=u->l->s;
    else
        u->w=u->p->w,u->s=u->p->s;
}
pii getwart(int a,int b,int lo,int hi,Node *u)
{
    if(b<=a)
        return mp(inf,0);
    if(a==lo&&b==hi)
        return mp(u->s,u->w);
    int mid=(lo+hi)/2;
    pii L=mp(inf,0),P=mp(inf,0);
    if(u->l!=NULL)
        L=getwart(a,min(b,mid),lo,mid,u->l);
    if(u->p!=NULL)
        P=getwart(max(a,mid),b,mid,hi,u->p);
    if(L.st==P.st)
        return mp(L.st,(L.nd+P.nd)%mod);
    else if(L.st<P.st)
        return L;
    else
        return P;
}
int main()
{
    speed
    int n;
    cin>>n;
    ll suma=1;
    while(suma<inf)
        suma*=2;
    suma*=2;
    suma--;
    for(int i=1; i<=n; i++)
        cin>>T[i].st>>T[i].nd;
    sort(T+1,T+n+1,cmp);
    Node *k=new Node();
    int wynik=0,mini=inf;
    for(int i=1; i<=n; i++)
    {
       // cout<<i<<" def "<<T[i].st<<" "<<T[i].nd<<endl;
        pii x=getwart(T[i].st,suma/2+2,1,suma/2+2,k);
        //cout<<"dziala"<<endl;
        int s;
        if(x.st==inf)
            s=T[i].nd,x.nd=1;
        else
            s=x.st-T[i].st+T[i].nd;
        ustaw(T[i].nd,T[i].nd+1,1,suma/2+2,k,s,x.nd);
        // cout<<"ok"<<endl;
        //cout<<"czesciowka "<<s<<" "<<x.nd<<endl;
        if(i==n||T[i].nd<T[n].st)
        {
           // cout<<i<<endl;
           if(s==mini)
            wynik=(wynik+x.nd)%mod;
            else if(s<mini)
                wynik=x.nd,mini=s;
        }

    }
    cout<<wynik;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
const int mod=1000000007;
//const int mod=998244353;
const int inf=1000000009;
const long long int INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.0000000001;
using namespace std;
pii T[200005];
bool cmp(pii a,pii b)
{
    if(a.st!=b.st)
        return a.st>b.st;
    return a.nd>b.nd;
}
int DP[200005];
struct Node
{
    int s=inf,w=1;
    Node *l=NULL,*p=NULL;
};
void ustaw(int a,int b,int lo,int hi,Node *u,int s,int w)
{
    if(b<=a)
        return;
    if(a==lo&&b==hi)
    {
        if(u->s==s)
            u->w=(u->w+w)%mod;
        else if(u->s>s)
            u->w=w;
        return;
    }
    int mid=(lo+hi)/2;
    if(u->l==NULL)
        u->l=new Node();
    if(u->p==NULL)
        u->p=new Node();
        ustaw(a,min(b,mid),lo,mid,u->l,s,w);
        ustaw(max(a,mid),b,mid,hi,u->p,s,w);

     if(u->l->s==u->p->s)
        u->w=(u->l->w+u->p->w)%mod;
    else if(u->l->s<u->p->s)
        u->w=u->l->w;
    else
        u->w=u->p->w;
}
pii getwart(int a,int b,int lo,int hi,Node *u)
{
    if(b<=a)
        return mp(inf,0);
    if(a==lo&&b==hi)
        return mp(u->s,u->w);
    int mid=(lo+hi)/2;
    pii L=mp(inf,0),P=mp(inf,0);
    if(u->l!=NULL)
        L=getwart(a,min(b,mid),lo,mid,u->l);
    if(u->p!=NULL)
        P=getwart(max(a,mid),b,mid,hi,u->p);
    if(L.st==P.st)
        return mp(L.st,(L.st+P.st)%mod);
    else if(L.st<P.st)
        return L;
    else
        return P;
}
int main()
{
    speed
    int n;
    cin>>n;
    ll suma=1;
    while(suma<inf)
        suma*=2;
    suma*=2;
    suma--;
    for(int i=1; i<=n; i++)
        cin>>T[i].st>>T[i].nd;
    sort(T+1,T+n+1,cmp);
    Node *k=new Node();
    int wynik=0;
    for(int i=1; i<=n; i++)
    {
        pii x=getwart(T[i].st,suma/2+2,1,suma/2+2,k);
        cout<<"dziala"<<endl;
        int s;
        if(x.st==inf)
            s=T[i].nd;
        else
            s=x.st-T[i].st+T[i].nd;
        ustaw(T[i].st,T[i].st+1,1,suma/2+2,k,s,x.nd);
        cout<<"ok"<<endl;
        if(i==n||T[i].nd<T[n].st)
            wynik=(wynik+x.nd)%mod;
    }
    return 0;
}


#include <bits/stdc++.h>

#define pii pair<int, int>
#define endl "\n"
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int INF = 1e9;
const double E = 1e-10;
const ll P = 1e9 + 7;
const ll Q = 31;

using namespace std;

void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    srand(time(0));
}

void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}

struct node
{
    node *left, *right;
    int key, prior;
    int val;
    int cnt, minn;
    int sz;
    node(int tkey)
    {
        left = right = nullptr;
        key = tkey;
        prior = rand();
        val = tkey;
        cnt = 0;
        minn = tkey;
        sz = 0;
    }
};

int dminn(node* root)
{
    if (!root)
        return INF;
    return root->minn;
}

void upd(node* root)
{
    if (!root)
        return;
    int v1 = dminn(root->left);
    int v2 = dminn(root->right);
    root->minn = min({root->val, v1, v2});
    root->cnt = 0;
    if (v1 == root->minn)
        root->cnt += root->left->cnt;
    if (v2 == root->minn)
        root->cnt += root->right->cnt;
    root->cnt %= P;
    if (root->val == root->minn)
        root->cnt += root->sz;
    root->cnt %= P;
}

node* merge(node* root1, node* root2)
{
    if (!root1)
        return root2;
    if (!root2)
        return root1;
    if (root1->prior > root2->prior)
    {
        root1->right = merge(root1->right, root2);
        upd(root1);
        return root1;
    }
    else
    {
        root2->left = merge(root1, root2->left);
        upd(root2);
        return root2;
    }
}

void split(node* root, int key, node*& left, node*& right)
{
    if (!root)
    {
        left = right = nullptr;
        return;
    }
    if (root->key > key)
    {
        split(root->left, key, left, root->left);
        upd(root);
        right = root;
    }
    else
    {
        split(root->right, key, root->right, right);
        upd(root);
        left = root;
    }
}

node* root = nullptr;

pii mres(int in, int out)
{
    node *left, *right;
    split(root, out - 1, left, right);
    pii res;
    if (!right)
        res = {in, 1};
    else
        res = {right->minn - out + in, right->cnt};
    root = merge(left, right);
    return res;
}

void show(node* root)
{
    if (!root)
        return;
    show(root->left);
    cout << root->key << " " << root->val << " " << root->minn << " " << root->sz << endl;
    show(root->right);
}

signed main()
{
    hello();

    int n;
    cin >> n;
    vector <pii> seq(n);
    int maxx = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> seq[i].second >> seq[i].first;
    }

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

    int val = INF, sz = 0;

    for (int i = n - 1; i >= 0; --i)
    {
        pii tmp = mres(seq[i].first, seq[i].second);
        //cout << tmp.first << " " << tmp.second << endl;
        if (tmp.first < val)
        {
            val = tmp.first;
            sz = tmp.second;
        }
        else if (tmp.first == val)
            sz += tmp.second;
        sz %= P;
        if (!i || seq[i].first != seq[i - 1].first)
        {
            //cout << i << "@" << endl;
            node* nnode = new node(seq[i].first);
            nnode->sz = nnode->cnt = sz;
            nnode->minn = nnode->val = val;
            val = INF;
            sz = 0;
            node *left, *right;
            split(root, nnode->key, left, right);
            root = merge(merge(left, nnode), right);
        }
        //cout << i << endl;
        //show(root);
        //cout << endl << endl;
    }

    cout << root->cnt << endl;

}


#include <bits/stdc++.h>

#define pii pair<int, int>
#define endl "\n"
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int INF = 1e9;
const double E = 1e-10;
const ll P = 1e9 + 7;
const ll Q = 31;

using namespace std;

void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}

signed main()
{
    hello();

    int n;
    cin >> n;
    map<int, int> mres;
    vector <pii> seq(n);
    int maxx = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> seq[i].second >> seq[i].first;
    }

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

    reverse(seq.begin(), seq.end());

    for (auto i : seq)
    {
        if (!mres.count(i.second) && i.second > seq[0].first)
            mres[i.second] = 1;

        mres[i.first] += mres[i.second];
        mres[i.first] %= P;
        //cout << i.first << " " << i.second << " " << mres[i.first] << " " << mres[i.second] << endl;
    }

    cout << mres.begin()->second << endl;
}


#include <bits/stdc++.h>

#define pii pair<int, int>
#define endl "\n"
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int INF = 1e9;
const double E = 1e-10;
const ll P = 1e9 + 7;
const ll Q = 31;

using namespace std;

void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}

signed main()
{
    hello();

    int n;
    cin >> n;
    map<int, int> mres;
    vector <pii> seq(n);
    int maxx = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> seq[i].second >> seq[i].first;
    }

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

    reverse(seq.begin(), seq.end());

    for (auto i : seq)
    {
        if (!mres.count(i.second) && i.second > seq[0].first)
            mres[i.second] = 1;
        if (!mres[i.second] && i.first == seq.back().first)
            mres[i.second] = 1;

        mres[i.first] += mres[i.second];
        mres[i.first] %= P;
        //cout << i.first << " " << i.second << " " << mres[i.first] << " " << mres[i.second] << endl;
    }

    int res = mres.begin()->second;
    cout << res << endl;
}


#include <bits/stdc++.h>

#define pii pair<int, int>
#define endl "\n"
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int INF = 1e9;
const double E = 1e-10;
const ll P = 1e9 + 7;
const ll Q = 31;

using namespace std;

void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    srand(time(0));
}

void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}

struct node
{
    node *left, *right;
    int key, prior;
    int val;
    int cnt, minn;
    int sz;
    node(int tkey)
    {
        left = right = nullptr;
        key = tkey;
        prior = rand();
        val = tkey;
        cnt = 0;
        minn = tkey;
        sz = 0;
    }
};

int dminn(node* root)
{
    if (!root)
        return INF;
    return root->minn;
}

void upd(node* root)
{
    if (!root)
        return;
    int v1 = dminn(root->left);
    int v2 = dminn(root->right);
    root->minn = min({root->val, v1, v2});
    root->cnt = 0;
    if (v1 == root->minn)
        root->cnt += root->left->cnt;
    if (v2 == root->minn)
        root->cnt += root->right->cnt;
    root->cnt %= P;
    if (root->val == root->minn)
        root->cnt += root->sz;
    root->cnt %= P;
}

node* merge(node* root1, node* root2)
{
    if (!root1)
        return root2;
    if (!root2)
        return root1;
    if (root1->prior > root2->prior)
    {
        root1->right = merge(root1->right, root2);
        upd(root1);
        return root1;
    }
    else
    {
        root2->left = merge(root1, root2->left);
        upd(root2);
        return root2;
    }
}

void split(node* root, int key, node*& left, node*& right)
{
    if (!root)
    {
        left = right = nullptr;
        return;
    }
    if (root->key > key)
    {
        split(root->left, key, left, root->left);
        upd(root);
        right = root;
    }
    else
    {
        split(root->right, key, root->right, right);
        upd(root);
        left = root;
    }
}

node* root = nullptr;

pii mres(int in, int out)
{
    node *left, *right;
    split(root, out - 1, left, right);
    pii res;
    if (!right)
        res = {in, 1};
    else
        res = {right->minn - out + in, right->cnt};
    root = merge(left, right);
    return res;
}

void show(node* root)
{
    if (!root)
        return;
    show(root->left);
    cout << root->key << " " << root->val << " " << root->minn << " " << root->sz << endl;
    show(root->right);
}

signed main()
{
    hello();

    int n;
    cin >> n;
    vector <pii> seq(n);
    int maxx = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> seq[i].second >> seq[i].first;
    }

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

    int val = INF, sz = 0;

    for (int i = n - 1; i >= 0; --i)
    {
        pii tmp = mres(seq[i].first, seq[i].second);
        //cout << tmp.first << " " << tmp.second << endl;
        if (tmp.first < val)
        {
            val = tmp.first;
            sz = tmp.second;
        }
        else if (tmp.first == val)
            sz += tmp.second;
        sz %= P;
        if (!i || seq[i].first != seq[i - 1].first)
        {
            //cout << i << "@" << endl;
            node* nnode = new node(seq[i].first);
            nnode->sz = nnode->cnt = sz;
            nnode->val = val;
            val = INF;
            sz = 0;
            node *left, *right;
            split(root, nnode->key, left, right);
            root = merge(merge(left, nnode), right);
        }
        //cout << i << endl;
        //show(root);
        //cout << endl << endl;
    }

    cout << root->cnt << endl;

}


#include <bits/stdc++.h>

#define pii pair<int, int>
#define endl "\n"
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int INF = 1e18;
const double E = 1e-10;
const ll P = 1e9 + 7;
const ll Q = 31;

using namespace std;

void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    srand(time(0));
}

void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}

struct node
{
    node *left, *right;
    int key, prior;
    int val;
    int cnt, minn;
    int sz;
    node(int tkey)
    {
        left = right = nullptr;
        key = tkey;
        prior = rand();
        val = tkey;
        cnt = 0;
        minn = tkey;
        sz = 0;
    }
};

int dminn(node* root)
{
    if (!root)
        return INF;
    return root->minn;
}

void upd(node* root)
{
    if (!root)
        return;
    int v1 = dminn(root->left);
    int v2 = dminn(root->right);
    root->minn = min({root->val, v1, v2});
    root->cnt = 0;
    if (v1 == root->minn)
        root->cnt += root->left->cnt;
    if (v2 == root->minn)
        root->cnt += root->right->cnt;
    root->cnt %= P;
    if (root->val == root->minn)
        root->cnt += root->sz;
    root->cnt %= P;
}

node* merge(node* root1, node* root2)
{
    if (!root1)
        return root2;
    if (!root2)
        return root1;
    if (root1->prior > root2->prior)
    {
        root1->right = merge(root1->right, root2);
        upd(root1);
        return root1;
    }
    else
    {
        root2->left = merge(root1, root2->left);
        upd(root2);
        return root2;
    }
}

void split(node* root, int key, node*& left, node*& right)
{
    if (!root)
    {
        left = right = nullptr;
        return;
    }
    if (root->key > key)
    {
        split(root->left, key, left, root->left);
        upd(root);
        right = root;
    }
    else
    {
        split(root->right, key, root->right, right);
        upd(root);
        left = root;
    }
}

node* root = nullptr;

pii mres(int in, int out)
{
    node *left, *right;
    split(root, out - 1, left, right);
    pii res;
    if (!right)
        res = {in, 1};
    else
        res = {right->minn - out + in, right->cnt};
    root = merge(left, right);
    return res;
}

void show(node* root)
{
    if (!root)
        return;
    show(root->left);
    cout << root->key << " " << root->val << " " << root->minn << " " << root->sz << endl;
    show(root->right);
}

signed main()
{
    hello();

    int n;
    cin >> n;
    vector <pii> seq(n);
    int maxx = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> seq[i].second >> seq[i].first;
    }

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

    int val = INF, sz = 0;

    for (int i = n - 1; i >= 0; --i)
    {
        pii tmp = mres(seq[i].first, seq[i].second);
        //cout << tmp.first << " " << tmp.second << endl;
        if (tmp.first < val)
        {
            val = tmp.first;
            sz = tmp.second;
        }
        else if (tmp.first == val)
            sz += tmp.second;
        sz %= P;
        if (!i || seq[i].first != seq[i - 1].first)
        {
            //cout << i << "@" << endl;
            node* nnode = new node(seq[i].first);
            nnode->sz = nnode->cnt = sz;
            nnode->val = val;
            val = INF;
            sz = 0;
            node *left, *right;
            split(root, nnode->key, left, right);
            root = merge(merge(left, nnode), right);
        }
        //cout << i << endl;
        //show(root);
        //cout << endl << endl;
    }

    cout << root->cnt << endl;

}


#include <bits/stdc++.h>
template<typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from, int to, T cost) {
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
};
bool operator == (Edge<int> e1, Edge<int> e2) {
    return e1.from == e2.from &&
            e1.to == e2.to &&
            e1.cost == e2.cost;
}
bool operator > (Edge<int> e1, Edge<int> e2) {
    return e1.cost < e2.cost;
}
template<typename T>
using Edges = std::vector<Edge<T>>;
template<typename T>
using Graph = std::vector<Edges<T>>;
template <typename T>
std::vector<T> dijkstra(const Graph<T> &g, int s) {
    int sz = (int)(g.size());
    std::vector<T> dist(sz, -1);
    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> pq;
    dist[s] = 0;
    pq.push({0, s});
    while(!pq.empty()) {
        T d = pq.top().first;
        int now = pq.top().second;
        pq.pop();
        if(dist[now] == -1 || d > dist[now]) continue;
        for(int i=0;i<(int)(g[now].size());++i) {
            int next = g[now][i].to;
            T cost = g[now][i].cost;
            if(dist[next] == -1 || dist[next] > dist[now] + cost) {
                dist[next] = dist[now] + cost;
                pq.push({cost, next});
            }
        }
    }
    return dist;
}
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const ll INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(ll i=0;i<(ll)(s.size());++i) {
    cout << s[i];
    if(i == (ll)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  ll n; cin >> n;
  Graph<ll> g(2*n+1);
  map<ll, ll> mp;
  vector<pair<P, ll>> v;
  ll idx = 1;
  set<ll> st;
  st.insert(0);
  mp[0] = 0;
  ll ma = 0;
  for(ll i=0;i<n;++i) {
    ll a, b; cin >> a >> b;
    v.push_back({{b, a}, 0});
    ma = max(ma, b);
    st.insert(a);
    st.insert(b);
    if(mp.find(a) == mp.end()) {
      mp[a] = idx;
      idx++;
    }
    if(mp.find(b) == mp.end()) {
      mp[b] = idx;
      idx++;
    }
    g[mp[b]].push_back(Edge<ll>(mp[b], mp[a], 0));
  }
  ll prev = -1;
  for(auto &e: st) {
    if(prev == -1) {
      prev = e;
    } else {
      g[mp[prev]].push_back(Edge<ll>(mp[prev], mp[e], e - prev));
      v.push_back({{prev, e}, e - prev});
      prev = e;
    }
  }
  sort(v.begin(), v.end());
  vector<ll> d = dijkstra(g, mp[0]);
  ll mi = LINF;
  for(auto &e: st) {
    if(e > ma) {
      mi = min(mi, d[mp[e]]);
    }
  }
  vector<ll> dp(2*n+1, 0);
  dp[mp[0]] = 1;
  for(const auto &e: v) {
    ll u = e.first.first, v = e.first.second;
    ll cost = e.second;
    if(d[mp[v]] == d[mp[u]] + cost) {
      dp[mp[v]] += dp[mp[u]];
      dp[mp[v]] %= MOD;
    }
  }
  ll ans = 0;
  for(const auto &e: st) {
    if(e > ma && d[mp[e]] == mi) {
      ans += dp[mp[e]];
      ans %= MOD;
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
template<typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from, int to, T cost) {
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
};
bool operator == (Edge<int> e1, Edge<int> e2) {
    return e1.from == e2.from &&
            e1.to == e2.to &&
            e1.cost == e2.cost;
}
bool operator > (Edge<int> e1, Edge<int> e2) {
    return e1.cost < e2.cost;
}
template<typename T>
using Edges = std::vector<Edge<T>>;
template<typename T>
using Graph = std::vector<Edges<T>>;
template <typename T>
std::vector<T> dijkstra(const Graph<T> &g, int s) {
    int sz = (int)(g.size());
    std::vector<T> dist(sz, -1);
    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> pq;
    dist[s] = 0;
    pq.push({0, s});
    while(!pq.empty()) {
        T d = pq.top().first;
        int now = pq.top().second;
        pq.pop();
        if(dist[now] == -1 || d > dist[now]) continue;
        for(int i=0;i<(int)(g[now].size());++i) {
            int next = g[now][i].to;
            T cost = g[now][i].cost;
            if(dist[next] == -1 || dist[next] > dist[now] + cost) {
                dist[next] = dist[now] + cost;
                pq.push({cost, next});
            }
        }
    }
    return dist;
}
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const ll INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(ll i=0;i<(ll)(s.size());++i) {
    cout << s[i];
    if(i == (ll)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  ll n; cin >> n;
  Graph<ll> g(2*n+1);
  map<ll, ll> mp;
  vector<pair<P, ll>> v;
  ll idx = 1;
  set<ll> st;
  st.insert(0);
  mp[0] = 0;
  ll ma = 0;
  for(ll i=0;i<n;++i) {
    ll a, b; cin >> a >> b;
    v.push_back({{b, a}, 0});
    ma = max(ma, b);
    st.insert(a);
    st.insert(b);
    if(mp.find(a) == mp.end()) {
      mp[a] = idx;
      idx++;
    }
    if(mp.find(b) == mp.end()) {
      mp[b] = idx;
      idx++;
    }
    g[mp[b]].push_back(Edge<ll>(mp[b], mp[a], 0));
  }
  ll prev = -1;
  for(auto &e: st) {
    if(prev == -1) {
      prev = e;
    } else {
      g[mp[prev]].push_back(Edge<ll>(mp[prev], mp[e], e - prev));
      v.push_back({{prev, e}, e - prev});
      prev = e;
    }
  }
  sort(v.begin(), v.end());
  vector<ll> d = dijkstra(g, mp[0]);
  ll mi = LINF;
  for(auto &e: st) {
    if(e > ma) {
      mi = min(mi, d[mp[e]]);
    }
  }
  vector<ll> dp(2*n+1, 0);
  dp[mp[0]] = 1;
  for(const auto &e: v) {
    ll u = e.first.first, v = e.first.second;
    ll cost = e.second;
    if(d[mp[v]] == d[mp[u]] + cost) {
      dp[mp[v]] += dp[mp[u]];
    }
  }
  ll ans = 0;
  for(const auto &e: st) {
    if(e > ma && d[mp[e]] == mi) {
      ans += dp[mp[e]];
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
#include "../lib/graph/graph.hpp"
#include "../lib/graph/dijkstra.hpp"

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
#define int ll
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  Graph<ll> g(2*n+1);
  map<int, int> mp;
  vector<pair<P, int>> v;
  int idx = 1;
  set<int> st;
  st.insert(0);
  mp[0] = 0;

  int ma = 0;
  for(int i=0;i<n;++i) {
    int a, b; cin >> a >> b;
    v.push_back({{b, a}, 0});
    ma = max(ma, b);
    st.insert(a);
    st.insert(b);
    if(mp.find(a) == mp.end()) {
      mp[a] = idx;
      idx++;
    }
    if(mp.find(b) == mp.end()) {
      mp[b] = idx;
      idx++;
    }
    g[mp[b]].push_back(Edge<ll>(mp[b], mp[a], 0));
  }

  int prev = -1;
  for(auto &e: st) {
    if(prev == -1) {
      prev = e;
    } else {
      //cout << prev << ":" << e << endl;
      g[mp[prev]].push_back(Edge<ll>(mp[prev], mp[e], e - prev));
      v.push_back({{prev, e}, e - prev});
      prev = e;
    }
  }
  sort(v.begin(), v.end());

  vector<ll> d = dijkstra(g, mp[0]);
  //printv(d);

  ll mi = LINF;
  for(auto &e: st) {
    //cout << e << ":" << mp[e] << endl;
    if(e > ma) {
      //cout << d[mp[e]] << endl;
      mi = min(mi, d[mp[e]]);
    }
  }

  vector<ll> dp(2*n+1, 0);
  dp[mp[0]] = 1;

  for(const auto &e: v) {
    int u = e.first.first, v = e.first.second;
    ll cost = e.second;
    //cout << u << ":" << v << ":" << cost << endl;
    //cout << d[mp[v]] << ":" << d[mp[u]] << endl;
    if(d[mp[v]] == d[mp[u]] + cost) {
      dp[mp[v]] += dp[mp[u]];
    }
  }
  //printv(dp);

  ll ans = 0;
  for(const auto &e: st) {

    if(e > ma && d[mp[e]] == mi) {
      ans += dp[mp[e]];
    }
  }
  cout << ans << endl;

}


#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 10000000000000009
#define N 1000005
using namespace std;

typedef long long ll;
typedef pair < ll , ll > ii;

ll n, m, k, ans, a[N], pre[N], of[N], mx[14];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("outt.txt", "w", stdout);
	scanf("%lld %lld %lld",&n ,&m ,&k);
	for(ll i = 0; i < n; i++){
		scanf("%lld",a + i);
	}
	pre[0] = a[0];
	for(ll i = 1; i < n; i++)
		pre[i] = pre[i - 1] + a[i];
	for(ll i = 0; i < n; i++)
		of[i] = i/m;
	for(ll i = 0; i < m; i++)
		mx[i] = -inf;
	for(ll i = n - 1; i >= 0; i--){
		mx[i%m] = max(mx[i%m], -i/m*k + pre[i]);
		// cout << i << " " << ans << endl;
		for(ll j = 0; j < m; j++){
			// cout << j << " " << mx[j] << " " << pre[i] << " " << i/m*k << " " << ((i==0)?0:pre[i - 1]) - i/m*k + (j >= i%m)*k << endl;
			ans = max(ans, mx[j] - ((i==0)?0:pre[i - 1]) + i/m*k - (j >= i%m)*k);
		}
		// cout << i << " " << ans << endl;
	}
	printf("%lld\n", ans);

	return 0;
}


#include <bits/stdc++.h>

const int N = 200010;
const int moder = (int) 1e9 + 7;
const int MAX = 1 << 18;
typedef std::pair <int, int> pii;

pii p[N];
pii seg[MAX << 1];
pii ans[N];
int seg1[MAX << 1];

pii merge(pii p1, pii p2){
    if (p1.first != p2.first){
        return std::min(p1, p2);
    }
    int x = p1.second + p2.second;
    x -= x >= moder ? moder : 0;
    return {p1.first, x};
}

void add(int sit, pii p){
    seg[sit += MAX] = p;
    for (sit >>= 1; sit; sit >>= 1){
        seg[sit] = merge(seg[sit << 1], seg[sit << 1 | 1]);
    }
}

pii query(int l, int r){
    pii ret = {INT_MAX, 0};
    for (l += MAX, r += MAX + 1; l < r; l >>= 1, r >>= 1){
        if (l & 1) ret = merge(ret, seg[l ++]);
        if (r & 1) ret = merge(ret, seg[-- r]);
    }
    return ret;
}

void add(int sit, int p){
    seg1[sit += MAX] = p;
    for (sit >>= 1; sit; sit >>= 1){
        seg1[sit] = std::max(seg1[sit << 1], seg1[sit << 1 | 1]);
    }
}

int query1(int l, int r){
    int ret = 0;
    for (l += MAX, r += MAX + 1; l < r; l >>= 1, r >>= 1){
        if (l & 1) ret = std::max(ret, seg1[l ++]);
        if (r & 1) ret = std::max(ret, seg1[-- r]);
    }
    return ret;
}

int main(){
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i){
        int a, b;
        scanf("%d%d", &a, &b);
        p[i] = {a, b};
    }
    std::sort(p, p + n);
    int maxsit = -1;
    for (int i = 0; i < n; ++ i){
        int sit = std::lower_bound(p, p + n, (pii){p[i].second, INT_MAX}) - p - 1;
        pii q = query(query1(0, sit), sit);
        add(i, sit);
        pii nq = {p[i].second - p[i].first, 1};
        if (q.first == INT_MAX){
            add(i, nq);
        }
        else {
            q.first += p[i].second - p[i].first;
            nq = merge(q, nq);
            add(i, nq);
        }
        nq.first += p[i].first;
        ans[i] = nq;
        maxsit = std::max(maxsit, sit);
    }
    pii ret = {INT_MAX, 0};
    int max = -1;
    for (int i = 0; i < n; ++ i){
        max = std::max(max, seg1[i + MAX]);
    }
    for (int i = max + 1; i < n; ++ i){
        ret = merge(ans[i], ret);
    }
    printf("%d\n", ret.second);
    return 0;
}


#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define debug(x) cerr<<#x<<" = "<<(x)<<endl
#define eps 1e-8
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN=(int)2e5+5;
const int MOD=(int)1e9+7;
int dp[MAXN];
ll mi[MAXN];
vector<int>ve,vp[MAXN];
int in[MAXN],out[MAXN];
void up(int x,int y,int z){
    if(y>mi[x])return;
    if(y<mi[x]){
        mi[x]=y;
        dp[x]=z;
    }
    else {
        dp[x]+=z;
        if(dp[x]>=MOD)dp[x]-=MOD;
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n+1;i++){
        dp[i]=0;
        mi[i]=MOD;
    }
    int maxIn=0,minOut=MOD;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&out[i],&in[i]);
        ve.push_back(in[i]);
        maxIn=max(maxIn,in[i]);
        minOut=min(minOut,out[i]);
    }
    sort(ve.begin(),ve.end());
    ve.erase(unique(ve.begin(),ve.end()),ve.end());
    for(int i=1;i<=n;i++){
        in[i]=lower_bound(ve.begin(),ve.end(),in[i])-ve.begin()+1;
        vp[in[i]].push_back(out[i]);
    }
  ///  debug(minOut);
  int pos=1;
    for(int i=1;ve[i-1]<minOut;i++)dp[i]=1,mi[i]=0,pos=i;
    for(int i=1;i<=(int)ve.size();i++){
        for(auto p:vp[i]){
            int y=lower_bound(ve.begin(),ve.end(),p)-ve.begin()+1;
            if(y==(int)ve.size()+1){
                up(y,mi[i]+ve[i-1],dp[i]);
            }
            else {
                up(y,mi[i]+ve[i-1]-p,dp[i]);
            }
        }
        if(i>pos&&i<ve.size())up(i+1,mi[i],dp[i]);
        ///printf("%s %d %d\n","zzz",i,dp[i]);
    }
  ///  debug(mi[(int)ve.size()+1]);
    printf("%d\n",dp[(int)ve.size()+1]);

    return 0;
}


from sys import stdin
from itertools import repeat
from collections import defaultdict
from bisect import bisect
def main():
    n = int(stdin.readline())
    dat = map(int, stdin.read().split(), repeat(10, 2 * n))
    a = [(dat[i*2], dat[i*2+1]) for i in xrange(n)]
    a.sort()
    mod = 1000000007
    b = [(0, 0, 1)]
    q = -1
    L = defaultdict(int)
    L[0] = -1
    N = 1 << 18
    u = [(1001001001, 0)] * (N + N)
    for l, s in a:
        p = bisect(b, (s, 1001001001)) - 1
        if L[l] < p:
            L[l] = p
        if q < p:
            q = p
        lp, rp = L[b[p][0]] + 1 + N, p + 1 + N
        if b[-1][0] != l:
            p = len(b) - 1 + N
            u[p] = (b[-1][1] - b[-1][0], b[-1][2])
            while p > 1:
                p /= 2
                u[p] = u[p+p]
                if u[p][0] > u[p+p+1][0]:
                    u[p] = u[p+p+1]
                elif u[p][0] == u[p+p+1][0]:
                    u[p] = (u[p][0], (u[p][1] + u[p+p+1][1]) % mod)
        res = (1001001001, 0)
        while lp < rp:
            if lp & 1:
                if res[0] > u[lp][0]:
                    res = u[lp]
                elif res[0] == u[lp][0]:
                    res = (res[0], (res[1] + u[lp][1]) % mod)
                lp += 1
            if rp & 1:
                rp -= 1
                if res[0] > u[rp][0]:
                    res = u[rp]
                elif res[0] == u[rp][0]:
                    res = (res[0], (res[1] + u[rp][1]) % mod)
            lp /= 2
            rp /= 2
        r, x = res[0] + s, res[1]
        if b[-1][0] != l:
            b.append((l, r, x))
        elif b[-1][1] == r:
            b[-1] = (l, r, (b[-1][2] + x) % mod)
        elif b[-1][1] > r:
            b[-1] = (l, r, x)
    b = b[q+1:]
    mn = min(x[1] for x in b)
    ans = 0
    for x in b:
        if x[1] == mn:
            ans += x[2]
            if ans >= mod:
                ans -= mod
    print ans
main()


#include <bits/stdc++.h>

using namespace std;

const int P = 1e9 + 7;

class Tree {
public:
    int emp;
    int numvar;
    Tree* lc;
    Tree* rc;

    Tree() {
        emp = 2e9;
        numvar = 1;
        lc = NULL;
        rc = NULL;
    }

    pair <int, int> get(int l, int r, int tl = 1, int tr = 1e9) {
        if (tl > r || l > tr)
            return make_pair(2e9, 1);
        if (l <= tl && tr <= r)
            return make_pair(emp, numvar);

        pair <int, int> lans, rans;

        int tm = (tl + tr) / 2;

        if (lc == NULL)
            lans = make_pair(2e9, 1);
        else
            lans = lc->get(l, r, tl, tm);

        if (rc == NULL)
            rans = make_pair(2e9, 1);
        else
            rans = rc->get(l, r, tm + 1, tr);

        if (lans.first == 2e9 && rans.first == 2e9)
            return make_pair(2e9, 1);
        if (lans.first == rans.first)
            return make_pair(lans.first, (long long)(lans.second + rans.second) % P);
        if (lans.first < rans.first)
            return lans;
        return rans;
    }

    void update(int pos, int nemp, long long nnumvar, int tl = 1, int tr = 1e9) {
        if (tl == tr) {
            if (emp == 2e9 && nemp == 2e9)
                return;
            else if (nemp == emp)
                numvar = (long long)(numvar + nnumvar) % P;
            else if (nemp < emp) {
                emp = nemp;
                numvar = nnumvar;
            }
        }
        else {

            int tm = (tl + tr) / 2;
            if (pos <= tm) {
                if (lc == NULL)
                    lc = new Tree();
                lc->update(pos, nemp, nnumvar, tl, tm);
            }
            else {
                if (rc == NULL)
                    rc = new Tree();
                rc->update(pos, nemp, nnumvar, tm + 1, tr);
            }

            pair <int, int> lans, rans;
            if (lc == NULL)
                lans = make_pair(2e9, 1);
            else
                lans = make_pair(lc->emp, lc->numvar);

            if (rc == NULL)
                rans = make_pair(2e9, 1);
            else
                rans = make_pair(rc->emp, rc->numvar);

            if (lans.first == 2e9 && rans.first == 2e9) {
                emp = 2e9;
                numvar = 1;
            }
            else if (lans.first == rans.first) {
                emp = lans.first;
                numvar = (long long)(lans.second + rans.second) % P;
            }
            else if (lans.first < rans.first) {
                emp = lans.first;
                numvar = lans.second;
            }
            else {
                emp = rans.first;
                numvar = rans.second;
            }
        }
    }

};

int n;
vector <pair <int, int> > a;
Tree* tree;

int main() {
    ios_base::sync_with_stdio(false);

    tree = new Tree();

    cin >> n;
    for (int i = 0; i < n; i++) {
        int out, in;
        cin >> out >> in;
        a.push_back(make_pair(out, in));
    }

    sort(a.begin(), a.end(), greater <pair <int, int> >());

    for (const auto& e: a) {
        pair <int, int> pre = tree->get(e.first, 1e9);
        int nemp;
        if (pre.first == 2e9)
            nemp = e.second;
        else
            nemp = pre.first - e.first + e.second;

        tree->update(e.second, nemp, pre.second);
    }

    cout << tree->get(1, 1e9).second;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int P = 1e9 + 7;

class Tree {
public:
    int emp;
    long long numvar;
    Tree* lc;
    Tree* rc;
    int tl;
    int tr;

    Tree(int _tl, int _tr) {
        emp = 2e9;
        numvar = 1;
        lc = NULL;
        rc = NULL;
        tl = _tl;
        tr = _tr;
    }

    void createChildren() {
        int tm = (tl + tr) / 2;
        if (lc == NULL)
            lc = new Tree(tl, tm);
        if (rc == NULL)
            rc = new Tree(tm + 1, tr);
    }

    pair <int, long long> get(int l, int r) {
        if (tl > r || l > tr)
            return make_pair(2e9, 1);
        if (l <= tl && tr <= r)
            return make_pair(emp, numvar);

        createChildren();
        pair <int, long long> lans = lc->get(l, r);
        pair <int, long long> rans = rc->get(l, r);
        if (lans.first == 2e9 && rans.first == 2e9)
            return make_pair(2e9, 1);
        if (lans.first == rans.first)
            return make_pair(lans.first, (lans.second + rans.second) % P);
        if (lans.first < rans.first)
            return lans;
        return rans;
    }

    void update(int pos, int nemp, long long nnumvar) {
        if (pos < tl || pos > tr)
            return;
        else if (tl == tr) {
            if (emp == 2e9 && nemp == 2e9)
                return;
            else if (nemp == emp)
                numvar = (numvar + nnumvar) % P;
            else if (nemp < emp) {
                emp = nemp;
                numvar = nnumvar;
            }
        }
        else {
            createChildren();
            lc->update(pos, nemp, nnumvar);
            rc->update(pos, nemp, nnumvar);

            if (lc->emp == 2e9 && rc->emp == 2e9) {
                emp = 2e9;
                numvar = 1;
            }
            else if (lc->emp == rc->emp) {
                emp = lc->emp;
                numvar = (lc->numvar + rc->numvar) % P;
            }
            else if (lc->emp < rc->emp) {
                emp = lc->emp;
                numvar = lc->numvar;
            }
            else {
                emp = rc->emp;
                numvar = rc->numvar;
            }
        }
    }

};

int n;
vector <pair <int, int> > a;
Tree* tree;

int main() {
    ios_base::sync_with_stdio(false);

    tree = new Tree(1, 1e9);

    cin >> n;
    for (int i = 0; i < n; i++) {
        int out, in;
        cin >> out >> in;
        a.push_back(make_pair(out, in));
    }

    sort(a.begin(), a.end(), greater <pair <int, int> >());

    for (const auto& e: a) {
        pair <int, long long> pre = tree->get(e.first, 1e9);
        int nemp;
        if (pre.first == 2e9)
            nemp = e.second;
        else
            nemp = pre.first - e.first + e.second;

        tree->update(e.second, nemp, pre.second);
    }

    cout << tree->get(1, 1e9).second;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int P = 1e9 + 7, N = 2e5 + 10;

int n;
vector <pair <int, int> > a;
pair <int, int> t[4 * N];

pair <int, int> get(int v, int tl, int tr, int l, int r) {
    if (l > tr || tl > r)
        return make_pair(2e9, 1);
    if (l <= tl && tr <= r)
        return t[v];
    int tm = (tl + tr) / 2;
    pair <int, int> lans = get(v * 2, tl, tm, l, r);
    pair <int, int> rans = get(v * 2 + 1, tm + 1, tr, l, r);
    if (lans.first == 2e9 && rans.first == 2e9)
        return make_pair(2e9, 1);
    if (lans.first == rans.first)
        return make_pair(lans.first, (lans.second + rans.second) % P);
    if (lans.first < rans.first)
        return lans;
    return rans;
}

void update(int v, int tl, int tr, int pos, int emp, int numvar) {
    if (tl == tr) {
        if (t[v].first == 2e9 && emp == 2e9)
            return;
        else if (t[v].first == emp)
            t[v].second = (t[v].second + numvar) % P;
        else if (t[v].first > emp)
            t[v] = make_pair(emp, numvar);
    }
    else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v * 2, tl, tm, pos, emp, numvar);
        else
            update(v * 2 + 1, tm + 1, tr, pos, emp, numvar);
        if (t[v * 2].first == 2e9 && t[v * 2 + 1].first == 2e9)
            t[v] = make_pair(2e9, 1);
        else if (t[v * 2].first == t[v * 2 + 1].first)
            t[v] = make_pair(t[v * 2].first, (t[v * 2].second + t[v * 2 + 1].second) % P);
        else if (t[v * 2].first < t[v * 2 + 1].first)
            t[v] = t[v * 2];
        else
            t[v] = t[v * 2 + 1];
    }
}

int main() {
    ios_base::sync_with_stdio(false);

    cin >> n;
    for (int i = 0; i < n; i++) {
        int out, in;
        cin >> out >> in;
        a.push_back(make_pair(in, out));
    }

    for (int i = 0; i < 4 * N; i++)
        t[i] = make_pair(2e9, 1);

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

    for (int i = (int)a.size() - 1; i >= 0; i--) {
        auto e = a[i];
        int pos = lower_bound(a.begin() + i, a.end(), make_pair(e.second, 0)) - a.begin();
        int emp, nvar;
        tie(emp, nvar) = get(1, 0, n, pos, n);
        if (emp == 2e9)
            emp = a[i].first;
        else
            emp = emp - a[i].second + a[i].first;
        update(1, 0, n, i, emp, nvar);
    }

    cout << get(1, 0, n, 0, n).second;

    return 0;
}


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

#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >

const int N = 2e5 + 7;
const int mod = 1e9 + 7;

pi a[N], dp[N], sf[N];
int n;

main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        scanf("%d%d", &a[i].sc, &a[i].fr);
    }
    sort(a + 1, a + n + 1);
    int mn = mod;
    dp[n].fr = a[n].fr;
    dp[n].sc = 1;
    sf[n] = dp[n];
    for (int i = n - 1; i >= 1; i--){
        int l = i + 1, r = n;
        while (l + 1 < r){
            int mid = (l + r) >> 1;
            if (a[mid].fr >= a[i].sc)
                r = mid;
            else
                l = mid;
        }
        if (a[l].fr >= a[i].sc)
            r = l;
        sf[i].fr = sf[i + 1].fr;
        sf[i].sc = sf[i + 1].sc;
        if (a[r].fr < a[i].sc){
            dp[i].fr = a[i].fr;
            dp[i].sc = 1;
        }
        else {
            dp[i].fr = sf[r].fr - (a[i].sc - a[i].fr);
            dp[i].sc = sf[r].sc;
        }
        if (sf[i].fr > dp[i].fr){
            sf[i].fr = dp[i].fr;
            sf[i].sc = dp[i].sc;
        }
        else if (sf[i].fr == dp[i].fr){
            sf[i].fr = dp[i].fr;
            sf[i].sc = (dp[i].sc + sf[i + 1].sc) % mod;
        }
        mn = min(mn, dp[i].fr);
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++){
        if (dp[i].fr == mn){
            ans += dp[i].sc;
            ans %= mod;
        }
    }
    cout << ans;
}


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

#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >

const int N = 2e5 + 7;
const int mod = 1e9 + 7;

pi a[N], dp[N], sf[N];
int n;

main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        scanf("%d%d", &a[i].sc, &a[i].fr);
    }
    if (n == 1){
        puts("1");
        return 0;
    }
    sort(a + 1, a + n + 1);
    int mn = mod;
    dp[n].fr = a[n].fr;
    dp[n].sc = 1;
    sf[n] = dp[n];
    for (int i = n - 1; i >= 1; i--){
        int l = i + 1, r = n;
        while (l + 1 < r){
            int mid = (l + r) >> 1;
            if (a[mid].fr >= a[i].sc)
                r = mid;
            else
                l = mid;
        }
        if (a[l].fr >= a[i].sc)
            r = l;
        sf[i].fr = sf[i + 1].fr;
        sf[i].sc = sf[i + 1].sc;
        if (a[r].fr < a[i].sc){
            dp[i].fr = a[i].fr;
            dp[i].sc = 1;
        }
        else {
            dp[i].fr = sf[r].fr - (a[i].sc - a[i].fr);
            dp[i].sc = sf[r].sc;
        }
        if (sf[i].fr > dp[i].fr){
            sf[i].fr = dp[i].fr;
            sf[i].sc = dp[i].sc;
        }
        else if (sf[i].fr == dp[i].fr){
            sf[i].fr = dp[i].fr;
            sf[i].sc = (dp[i].sc + sf[i + 1].sc) % mod;
        }
        mn = min(mn, dp[i].fr);
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++){
        if (dp[i].fr == mn){
            ans += dp[i].sc;
            ans %= mod;
        }
    }
    cout << ans;
}


#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;
    #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]);
        for (int j=1;j<i;++j)
        {
            if (a[j].out<=a[i].in)
            {
                if (f[j]-a[j].out+a[i].in<f[i])
                {
                    f[i]=f[j]-a[j].out+a[i].in;
                    g[i]=g[j];
                }
                else if (f[j]-a[j].out+a[i].in==f[i])
                {
                    add(g[i],g[j]);
                }
                //see(f[i]); seeln(g[i]);
            }
        }
        #ifdef DEBUG
        cout<<"f g:  "<<f[i]<<" "<<g[i]<<endl;
        #endif
    }
    int 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 <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;
    #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]);
        for (int j=1;j<i;++j)
        {
            if (a[j].out<=a[i].in)
            {
                if (f[j]-a[j].out+a[i].in<f[i])
                {
                    f[i]=f[j]-a[j].out+a[i].in;
                    g[i]=g[j];
                }
                else if (f[j]-a[j].out+a[i].in==f[i])
                {
                    add(g[i],g[j]);
                }
                see(f[i]); seeln(g[i]);
            }
        }
        #ifdef DEBUG
        cout<<"f g:  "<<f[i]<<" "<<g[i]<<endl;
        #endif
    }
    int mi=inf;
    for (int i=1;i<=n;++i)
    {
        if (f[i]<mi)
        {
            mi=f[i];
        }
    }
    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;
}