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

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

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

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

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

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

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

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

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

        if(idx != -1)
            return idx;

        return mid;
    }

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

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

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

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

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

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

//         else{

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

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

//             return mid;
//         }
//     }

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

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

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

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

    else{

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

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

        sum_table[idx] = 0;

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

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

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

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

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

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

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

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

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

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

        return idx;
    }

}

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

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

//     ll ans = 0;

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

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

//         sum_table[idx] = 1;

//         pt_data[idx].first = 0;

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

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

//         return ;
//     }

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

//         return ;
//     }

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

//     // getting the successor of the key

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

//     while(new_idx < idx){

//         new_idx--;
//     }

// }

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

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

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

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

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

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

    memo[idx] = ans;

    return ans;
}

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

    int n;

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

    cin >> n;

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

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

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

    }

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

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

        ll temp = findMinimum(arr, i);

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

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

    cout << finAns << endl;

    return 0;
}


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

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

vector<ll> memo, dp, sum_table, pt_data;

vector<pair<ll, int> > sorted_memo;

int itCount1 = 0, itCount2 = 0;

int stdrd_bin_search(ll num, pair<ll, ll> pt, vector<pair<ll, ll> >& pt_vec, int i, int j){

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

    int mid = (i+j)/2;

    pair<ll, int> temp = sorted_memo[mid];

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

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

            if(idx != -1)
                return idx;

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

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

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

int bin_search(pair<ll, ll> num, vector<pair<ll, ll> >& vec, int i, int j){
    itCount2++;
    if((j-i) < 0){
        return -1;
    }

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

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

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

        if(idx != -1)
            return idx;

        return mid;
    }

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

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

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

    else{

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

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

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

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

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

            return sum_table[sorted_memo[idx].second];

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

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

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

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

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

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

            }

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

}

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

    if(memo[idx] != -1){
        return memo[idx];
    }

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

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

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

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

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

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

    int n;

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

    cin >> n;

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

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

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

        memo.push_back(-1);
        dp.push_back(-1);
        sum_table.push_back(-1);
        pt_data.push_back(false);

    }

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

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

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

        ll temp = findMinimum(arr, i);

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

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

    // cout << "iteration count is " << itCount1 << " " << itCount2 << endl;
    sort(sorted_memo.begin(), sorted_memo.end());

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

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

    // cout << "iteration count is " << itCount1 << " " << itCount2 << endl;
    cout << finAns << endl;
    return 0;
}


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

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

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

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

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

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

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

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

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

        if(idx != -1)
            return idx;

        return mid;
    }

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

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

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

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

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

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

//         else{

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

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

//             return mid;
//         }
//     }

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

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

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

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

    else{

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

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

        sum_table[idx] = 0;

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

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

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

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

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

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

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

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

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

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

        return idx;
    }

}

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

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

//     ll ans = 0;

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

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

//         sum_table[idx] = 1;

//         pt_data[idx].first = 0;

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

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

//         return ;
//     }

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

//         return ;
//     }

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

//     // getting the successor of the key

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

//     while(new_idx < idx){

//         new_idx--;
//     }

// }

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

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

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

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

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

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

    memo[idx] = ans;

    return ans;
}

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

    int n;

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

    cin >> n;

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

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

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

    }

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

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

        ll temp = findMinimum(arr, i);

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

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

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

    cout << finAns << endl;

    return 0;
}


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

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

vector<ll> memo, dp, sum_table, pt_data;

vector<pair<ll, int> > sorted_memo;

int itCount = 0;

int stdrd_bin_search(ll num, pair<ll, ll> pt, vector<pair<ll, int> > vec, vector<pair<ll, ll> > pt_vec, int i, int j){

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

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

    pair<ll, int> temp = vec[mid];

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

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

            if(idx != -1)
                return idx;

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

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

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

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

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

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

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

        if(idx != -1)
            return idx;

        return mid;
    }

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

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

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

    else{

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

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

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

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

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

            return sum_table[sorted_memo[idx].second];

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

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

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

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

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

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

            }

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

}

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

    if(memo[idx] != -1){
        return memo[idx];
    }

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

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

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

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

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

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

    int n;

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

    cin >> n;

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

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

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

        memo.push_back(-1);
        dp.push_back(-1);
        sum_table.push_back(-1);
        pt_data.push_back(false);

    }

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

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

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

        ll temp = findMinimum(arr, i);

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

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

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

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

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

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

    // cout << "iteration count is " << itCount << endl;
    cout << finAns << endl;
    return 0;
}


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

#define MOD 1000000007
void mergesort(int* in, int* out, int left, int right){
    if(left>=right)
        return;

    int mid = (left+right)/2;
    mergesort(in, out, left, mid);
    mergesort(in, out, mid+1, right);

    int temp1[right-left+1], temp2[right-left+1];
    int i=left, j=mid+1, k=0;
    while(i<=mid&&j<=right){
        if(in[i]<in[j])
            temp1[k]=in[i], temp2[k]=out[i], i++;
        else if(in[i]>in[j])
            temp1[k]=in[j], temp2[k]=out[j], j++;
        else{
            if(out[i]<out[j])
               temp1[k]=in[i], temp2[k]=out[i], i++;
            else
               temp1[k]=in[j], temp2[k]=out[j], j++;
        }
        k++;
    }

    while(i<=mid)
        temp1[k]=in[i], temp2[k]=out[i], i++, k++;
    while(j<=right)
        temp1[k]=in[j], temp2[k]=out[j], j++, k++;

    for(k=0; k<right-left+1; k++)
        in[k+left]=temp1[k], out[k+left]=temp2[k];
}

int b_search_for_first(int*a, int no, int left, int right){
    if(left>right)
        return -1;

    if(left==right){
        if(a[left]==no)
            return left;
        return -1;
    }

    int mid = (left+right)/2;
    if(a[mid]>=no)
        return b_search_for_first(a, no, left, mid);

    return b_search_for_first(a, no, mid+1, right);
}

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

    long long cnt[n]; int in[n], out[n], position[n];
    for(int i=0; i<n; i++)
        scanf("%d%d", &out[i], &in[i]);

    for(int i=0; i<n; i++)
        position[i]=-1, cnt[i]=0;

    mergesort(in, out, 0, n-1);
    cnt[n-1] = 1;

    for(int i=n-2; i>=0; i--){
        if(out[i]>in[n-1])
            cnt[i]=1;
        int pos = b_search_for_first(in, out[i], i+1, n-1);
        if(pos!=-1)
            cnt[i]=cnt[pos], position[i]=pos;

        if(in[i]==in[i+1])
            cnt[i]=(cnt[i]+cnt[i+1])%MOD;
    }

    long long int ans = 0;
    for(int i=0; i<n&&in[i]==in[0]; i++)
    {
        if(position[i]!=-1)
            ans = (ans+cnt[position[i]])%MOD;
        else
            ans=(ans+1)%MOD;
    }

    printf("%lld\n", ans);
    return 0;
}


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

#define ABC 123
#define MOD 1000000007
void mergesort(int* in, int* out, int left, int right){
    if(left>=right)
        return;

    int mid = (left+right)/2;
    mergesort(in, out, left, mid);
    mergesort(in, out, mid+1, right);

    int temp1[right-left+1], temp2[right-left+1];
    int i=left, j=mid+1, k=0;
    while(i<=mid&&j<=right){
        if(in[i]<in[j])
            temp1[k]=in[i], temp2[k]=out[i], i++;
        else if(in[i]>in[j])
            temp1[k]=in[j], temp2[k]=out[j], j++;
        else{
            if(out[i]<out[j])
               temp1[k]=in[i], temp2[k]=out[i], i++;
            else
               temp1[k]=in[j], temp2[k]=out[j], j++;
        }
        k++;
    }

    while(i<=mid)
        temp1[k]=in[i], temp2[k]=out[i], i++, k++;
    while(j<=right)
        temp1[k]=in[j], temp2[k]=out[j], j++, k++;

    for(k=0; k<right-left+1; k++)
        in[k+left]=temp1[k], out[k+left]=temp2[k];
}

int first_greater_or_equal_to(int*a, int no, int left, int right){
    if(left>right)
        return -1;

    if(left==right){
        if(a[left]>=no)
            return left;
        return -1;
    }

    int mid = (left+right)/2;
    if(a[mid]<no)
        return first_greater_or_equal_to(a, no, mid+1, right);

    return first_greater_or_equal_to(a, no, left, mid);
}

int main(){
    int n; fstream f;
    #ifndef ABC
    f.open("inout.txt", ios::out|ios::in);
    f >> n;
    #else
       scanf("%d", &n);
    #endif
    int in[n], out[n];
    #ifndef ABC
        for(int i=0; i<n; i++)
            f>>out[i]>>in[i];
    #else
        for(int i=0; i<n; i++)
            scanf("%d%d", &out[i], &in[i]);
    #endif

    long long cnt[n+1],minm[n], min_val; int position[n];

    for(int i=0; i<n; i++)
        position[i]=-1, cnt[i]=0;

    mergesort(in, out, 0, n-1);
    cnt[n]=0, cnt[n-1] = 1, minm[n-1]=in[n-1], min_val=in[n-1];

    for(int i=n-2; i>=0; i--){
        int pos = first_greater_or_equal_to(in, out[i], i+1, n-1);
        if(pos!=-1)
            minm[i] = in[i]+minm[pos]-out[i],position[i]=pos,cnt[i]=cnt[pos];
        else
            minm[i]=in[i], position[i]=n, cnt[i]=1;

        if(minm[i]>minm[i+1])
            minm[i]=minm[i+1], position[i]=position[i+1], cnt[i]=cnt[i+1];

        else if(minm[i]==minm[i+1])
            cnt[i]=(cnt[i]+cnt[i+1])%MOD;

        min_val = min(min_val, minm[i]);
    }

    long long int ans = 0;
    for(int i=0; i<n&&minm[i]==min_val; i++)
    {
        if(position[i]!=-1)
            ans = ans+cnt[position[i]];
        else
            ans++;
    }
    #ifndef ABC
    if(f.is_open())
        f<<ans%MOD, f.close();
    #else
        printf("%lld\n",ans%MOD);
    #endif
    return 0;
}


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

#define ABC 123
#define MOD 1000000007
void mergesort(int* in, int* out, int left, int right){
    if(left>=right)
        return;

    int mid = (left+right)/2;
    mergesort(in, out, left, mid);
    mergesort(in, out, mid+1, right);

    int temp1[right-left+1], temp2[right-left+1];
    int i=left, j=mid+1, k=0;
    while(i<=mid&&j<=right){
        if(in[i]<in[j])
            temp1[k]=in[i], temp2[k]=out[i], i++;
        else if(in[i]>in[j])
            temp1[k]=in[j], temp2[k]=out[j], j++;
        else{
            if(out[i]<out[j])
               temp1[k]=in[i], temp2[k]=out[i], i++;
            else
               temp1[k]=in[j], temp2[k]=out[j], j++;
        }
        k++;
    }

    while(i<=mid)
        temp1[k]=in[i], temp2[k]=out[i], i++, k++;
    while(j<=right)
        temp1[k]=in[j], temp2[k]=out[j], j++, k++;

    for(k=0; k<right-left+1; k++)
        in[k+left]=temp1[k], out[k+left]=temp2[k];
}

int first_greater_or_equal_to(int*a, int no, int left, int right){
    if(left>right)
        return -1;

    if(left==right){
        if(a[left]>=no)
            return left;
        return -1;
    }

    int mid = (left+right)/2;
    if(a[mid]<no)
        return first_greater_or_equal_to(a, no, mid+1, right);

    return first_greater_or_equal_to(a, no, left, mid);
}

int main(){
    int n; fstream f;
    #ifndef ABC
    f.open("inout.txt", ios::out|ios::in);
    f >> n;
    #else
       scanf("%d", &n);
    #endif
    int in[n], out[n];
    #ifndef ABC
        for(int i=0; i<n; i++)
            f>>out[i]>>in[i];
    #else
        for(int i=0; i<n; i++)
            scanf("%d%d", &out[i], &in[i]);
    #endif

    long long cnt[n+1],minm[n], min_val; int position[n];

    for(int i=0; i<n; i++)
        position[i]=-1, cnt[i]=0;

    mergesort(in, out, 0, n-1);
    cnt[n]=0, cnt[n-1] = 1, minm[n-1]=in[n-1], min_val=in[n-1];

    for(int i=n-2; i>=0; i--){
        int pos = first_greater_or_equal_to(in, out[i], i+1, n-1);
        if(pos!=-1)
            minm[i] = in[i]+minm[pos]-out[i],position[i]=pos,cnt[i]=cnt[pos];
        else
            minm[i]=in[i], position[i]=n, cnt[i]=1;

        if(minm[i]>minm[i+1])
            minm[i]=minm[i+1], position[i]=position[i+1], cnt[i]=cnt[i+1];

        else if(minm[i]==minm[i+1])
            cnt[i]=(cnt[i]+cnt[i+1])%MOD;

        min_val = min(min_val, minm[i]);
    }

    /*long long int ans = 0;
    for(int i=0; i<n&&minm[i]==min_val; i++)
    {
        if(position[i]!=-1)
            ans = ans+cnt[position[i]];
        else
            ans++;
    }*/
    #ifndef ABC
    if(f.is_open()){
        f.close();
    }
    #endif

    printf("%lld\n",cnt[0]%MOD);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt(x) __builtin_popcount(x)
#define lbit(x) __builtin_ffsll(x)
#define rbit(x) (64 - __builtin_clzll(x))
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
#define sz(s) (ll) s.size()
#define cinfast() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << (x) << endl;
#define loop(x)                                                                \
    LCIN(loop);                                                                \
    while(loop--) {                                                            \
        x;                                                                     \
    }
#define PERM(c)                                                                \
    sort(All(c));                                                              \
    for(bool cp = true; cp; cp = next_permutation(All(c)))
#define COMB(n, k)                                                             \
    for(ll bit = (1LL << k) - 1; bit < (1LL << n); bit = next_combination(bit))
#define PERM2(n, k)                                                            \
    COMB(n, k) {                                                               \
        vector<int> sel;                                                       \
        for(int bitindex = 0; bitindex < n; bitindex++)                        \
            if(bit >> bitindex & 1) sel.emplace_back(bitindex);                \
        PERM(sel) { Printv(sel); }                                             \
    }
#define MKORDER(n)                                                             \
    vector<int> od(n);                                                         \
    iota(All(od), 0LL);

template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
template <class Head> inline void COUT(Head &&head) { cout << (head) << "\n"; }
template <class Head, class... Tail>
inline void COUT(Head &&head, Tail &&... tail) {
    cout << (head) << " ";
    COUT(forward<Tail>(tail)...);
}

#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    long long __VA_ARGS__;                                                     \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Printv(v)                                                              \
    {                                                                          \
        REP(hoge, v.size())                                                    \
        cout << v[hoge] << (hoge == v.size() - 1 ? "" : " ");                  \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

long long next_combination(long long sub) {
    long long x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
template <class T> inline bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

// generic lambdas
template <typename first>
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
[[nodiscard]]
#elif defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
__attribute__((warn_unused_result))
#endif // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
static inline constexpr decltype(auto)
fix(first &&f) noexcept {
    return [f = std::forward<first>(f)](auto &&... args) {
        return f(f, std::forward<decltype(args)>(args)...);
    };
}

template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll dw[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dh[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793230
#define EPS 1e-7

// 1000000007 で割ったあまりを扱う構造体
class mint {
  public:
    static long long MOD;
    long long val;
    mint(long long v = 0) noexcept : val(v % MOD) {
        if(val < 0) v += MOD;
    }
    int getmod() { return MOD; }
    mint operator-() const noexcept { return val ? MOD - val : 0; }
    mint operator+(const mint &r) const noexcept { return mint(*this) += r; }
    mint operator-(const mint &r) const noexcept { return mint(*this) -= r; }
    mint operator*(const mint &r) const noexcept { return mint(*this) *= r; }
    mint operator/(const mint &r) const noexcept { return mint(*this) /= r; }
    mint &operator+=(const mint &r) noexcept {
        val += r.val;
        val = (val + MOD) % MOD;
        return *this;
    }
    mint &operator-=(const mint &r) noexcept {
        val -= r.val;
        val = (val + MOD) % MOD;
        return *this;
    }
    mint &operator*=(const mint &r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    mint &operator/=(const mint &r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while(b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if(val < 0) val += MOD;
        return *this;
    }
    bool operator==(const mint &r) const noexcept { return this->val == r.val; }
    bool operator!=(const mint &r) const noexcept { return this->val != r.val; }
    friend ostream &operator<<(ostream &os, const mint &x) noexcept {
        return os << x.val;
    }
    friend istream &operator>>(istream &is, mint &x) noexcept {
        return is >> x.val;
    }
    friend mint modpow(const mint &a, long long n) noexcept {
        if(n == 0) return 1;
        mint t = modpow(a, n / 2);
        t = t * t;
        if(n & 1) t = t * a;
        return t;
    }
};
ll mint::MOD = 1e9 + 7;
ll const MAX_SIZE = 1e6 + 1;
mint inv[MAX_SIZE];
mint fact[MAX_SIZE];
mint factinv[MAX_SIZE];
void cominit() {
    inv[1] = 1;
    for(int i = 2; i < MAX_SIZE; i++) {
        inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
    }
    fact[0] = factinv[0] = 1;
    for(int i = 1; i < MAX_SIZE; i++) {
        fact[i] = mint(i) * fact[i - 1];
        factinv[i] = inv[i] * factinv[i - 1];
    }
}
mint comb(int n, int k) {
    if(n >= 0 && k >= 0 && n - k >= 0) {
        return fact[n] * factinv[k] * factinv[n - k];
    }
    return 0;
}
mint hcomb(ll n, ll k) {
    if(n == 0 && k == 0) return 1;
    return comb(n + k - 1, k);
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

void solve() {
    LCIN(N);
    ll ma = 0;
    VL com, os, is;
    REP(i, N) {
        LCIN(out, in);
        os.emplace_back(out);
        is.emplace_back(in);
        com.emplace_back(out);
        com.emplace_back(in);
    }
    sort(All(com));
    com.erase(unique(All(com)), com.end());
    VVL G(sz(com));
    REP(i, N) {
        ll idx = lower_bound(All(com), is[i]) - com.begin();
        ll odx = lower_bound(All(com), os[i]) - com.begin();
        chmax(ma, idx);
        G[idx].emplace_back(odx);
    }
    VL d(sz(com), LINF);
    vector<mint> cnt(sz(com));
    cnt[0] = 1, d[0] = com[0];
    REP(i, sz(com)) {
        ll val = com[i];
        if(i < sz(com) - 1) {
            if(d[i + 1] > d[i] + com[i + 1] - com[i]) {
                d[i + 1] = d[i] + com[i + 1] - com[i];
                cnt[i + 1] = cnt[i];
            } else if(d[i + 1] == d[i] + com[i + 1] - com[i]) {
                cnt[i + 1] += cnt[i];
            }
        }
        FOREACH(to, G[i]) {
            if(d[to] > d[i]) {
                d[to] = d[i];
                cnt[to] = cnt[i];
            } else if(d[to] == d[i]) {
                cnt[to] += cnt[i];
            }
        }
    }
    ll mi = LINF;
    mint ans = 0;
    FOR(i, ma + 1, sz(com)) {
        if(mi > d[i]) {
            mi = d[i];
            ans = cnt[i];
        } else if(mi == d[i]) {
            ans += cnt[i];
        }
    }
    COUT(ans);
}

signed main() {
    cinfast();
    // cout << fixed << setprecision(12);
    // loop(solve());
    solve();
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt(x) __builtin_popcount(x)
#define lbit(x) __builtin_ffsll(x)
#define rbit(x) (64 - __builtin_clzll(x))
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
#define sz(s) (ll) s.size()
#define cinfast() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << (x) << endl;
#define loop(x)                                                                \
    LCIN(loop);                                                                \
    while(loop--) {                                                            \
        x;                                                                     \
    }
#define PERM(c)                                                                \
    sort(All(c));                                                              \
    for(bool cp = true; cp; cp = next_permutation(All(c)))
#define COMB(n, k)                                                             \
    for(ll bit = (1LL << k) - 1; bit < (1LL << n); bit = next_combination(bit))
#define PERM2(n, k)                                                            \
    COMB(n, k) {                                                               \
        vector<int> sel;                                                       \
        for(int bitindex = 0; bitindex < n; bitindex++)                        \
            if(bit >> bitindex & 1) sel.emplace_back(bitindex);                \
        PERM(sel) { Printv(sel); }                                             \
    }
#define MKORDER(n)                                                             \
    vector<int> od(n);                                                         \
    iota(All(od), 0LL);

template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
template <class Head> inline void COUT(Head &&head) { cout << (head) << "\n"; }
template <class Head, class... Tail>
inline void COUT(Head &&head, Tail &&... tail) {
    cout << (head) << " ";
    COUT(forward<Tail>(tail)...);
}

#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    long long __VA_ARGS__;                                                     \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Printv(v)                                                              \
    {                                                                          \
        REP(hoge, v.size())                                                    \
        cout << v[hoge] << (hoge == v.size() - 1 ? "" : " ");                  \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

long long next_combination(long long sub) {
    long long x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
template <class T> inline bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

// generic lambdas
template <typename first>
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
[[nodiscard]]
#elif defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
__attribute__((warn_unused_result))
#endif // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
static inline constexpr decltype(auto)
fix(first &&f) noexcept {
    return [f = std::forward<first>(f)](auto &&... args) {
        return f(f, std::forward<decltype(args)>(args)...);
    };
}

template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll dw[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dh[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793230
#define EPS 1e-7

// 1000000007 で割ったあまりを扱う構造体
class mint {
  public:
    static long long MOD;
    long long val;
    mint(long long v = 0) noexcept : val(v % MOD) {
        if(val < 0) v += MOD;
    }
    int getmod() { return MOD; }
    mint operator-() const noexcept { return val ? MOD - val : 0; }
    mint operator+(const mint &r) const noexcept { return mint(*this) += r; }
    mint operator-(const mint &r) const noexcept { return mint(*this) -= r; }
    mint operator*(const mint &r) const noexcept { return mint(*this) *= r; }
    mint operator/(const mint &r) const noexcept { return mint(*this) /= r; }
    mint &operator+=(const mint &r) noexcept {
        val += r.val;
        val = (val + MOD) % MOD;
        return *this;
    }
    mint &operator-=(const mint &r) noexcept {
        val -= r.val;
        val = (val + MOD) % MOD;
        return *this;
    }
    mint &operator*=(const mint &r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    mint &operator/=(const mint &r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while(b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if(val < 0) val += MOD;
        return *this;
    }
    bool operator==(const mint &r) const noexcept { return this->val == r.val; }
    bool operator!=(const mint &r) const noexcept { return this->val != r.val; }
    friend ostream &operator<<(ostream &os, const mint &x) noexcept {
        return os << x.val;
    }
    friend istream &operator>>(istream &is, mint &x) noexcept {
        return is >> x.val;
    }
    friend mint modpow(const mint &a, long long n) noexcept {
        if(n == 0) return 1;
        mint t = modpow(a, n / 2);
        t = t * t;
        if(n & 1) t = t * a;
        return t;
    }
};
ll mint::MOD = 1e9 + 7;
ll const MAX_SIZE = 1e6 + 1;
mint inv[MAX_SIZE];
mint fact[MAX_SIZE];
mint factinv[MAX_SIZE];
void cominit() {
    inv[1] = 1;
    for(int i = 2; i < MAX_SIZE; i++) {
        inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
    }
    fact[0] = factinv[0] = 1;
    for(int i = 1; i < MAX_SIZE; i++) {
        fact[i] = mint(i) * fact[i - 1];
        factinv[i] = inv[i] * factinv[i - 1];
    }
}
mint comb(int n, int k) {
    if(n >= 0 && k >= 0 && n - k >= 0) {
        return fact[n] * factinv[k] * factinv[n - k];
    }
    return 0;
}
mint hcomb(ll n, ll k) {
    if(n == 0 && k == 0) return 1;
    return comb(n + k - 1, k);
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

void solve() {
    LCIN(N);
    ll ma = 0;
    VL com, os, is;
    REP(i, N) {
        LCIN(out, in);
        os.emplace_back(out);
        is.emplace_back(in);
        com.emplace_back(out);
        com.emplace_back(in);
    }
    sort(All(com));
    com.erase(unique(All(com)), com.end());
    VVL G(sz(com));
    REP(i, N) {
        ll idx = lower_bound(All(com), is[i]) - com.begin();
        ll odx = lower_bound(All(com), os[i]) - com.begin();
        chmax(ma, idx);
        G[idx].emplace_back(odx);
    }
    VL d(sz(com), LINF);
    vector<mint> cnt(sz(com));
    REP(i, sz(com)) {
        ll val = com[i];
        if(d[i] == LINF) {
            d[i] = (i ? d[i - 1] + com[i] - com[i - 1] : com[i]);
            cnt[i] += (i ? cnt[i - 1] : 1);
        }
        FOREACH(to, G[i]) {
            if(d[to] > d[i]) {
                d[to] = d[i];
                cnt[to] = cnt[i];
            } else if(d[to] == d[i]) {
                cnt[to] += cnt[i];
            }
        }
    }
    ll mi = LINF;
    mint ans = 0;
    FOR(i, ma + 1, sz(com)) {
        if(mi > d[i]) {
            mi = d[i];
            ans = cnt[i];
        } else if(mi == d[i]) {
            ans += cnt[i];
        }
    }
    COUT(ans);
}

signed main() {
    cinfast();
    // cout << fixed << setprecision(12);
    // loop(solve());
    solve();
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt(x) __builtin_popcount(x)
#define lbit(x) __builtin_ffsll(x)
#define rbit(x) (64 - __builtin_clzll(x))
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
#define sz(s) (ll) s.size()
#define cinfast() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << (x) << endl;
#define loop(x)                                                                \
    LCIN(loop);                                                                \
    while(loop--) {                                                            \
        x;                                                                     \
    }
#define PERM(c)                                                                \
    sort(All(c));                                                              \
    for(bool cp = true; cp; cp = next_permutation(All(c)))
#define COMB(n, k)                                                             \
    for(ll bit = (1LL << k) - 1; bit < (1LL << n); bit = next_combination(bit))
#define PERM2(n, k)                                                            \
    COMB(n, k) {                                                               \
        vector<int> sel;                                                       \
        for(int bitindex = 0; bitindex < n; bitindex++)                        \
            if(bit >> bitindex & 1) sel.emplace_back(bitindex);                \
        PERM(sel) { Printv(sel); }                                             \
    }
#define MKORDER(n)                                                             \
    vector<int> od(n);                                                         \
    iota(All(od), 0LL);

template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
template <class Head> inline void COUT(Head &&head) { cout << (head) << "\n"; }
template <class Head, class... Tail>
inline void COUT(Head &&head, Tail &&... tail) {
    cout << (head) << " ";
    COUT(forward<Tail>(tail)...);
}

#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    long long __VA_ARGS__;                                                     \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Printv(v)                                                              \
    {                                                                          \
        REP(hoge, v.size())                                                    \
        cout << v[hoge] << (hoge == v.size() - 1 ? "" : " ");                  \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

long long next_combination(long long sub) {
    long long x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
template <class T> inline bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

// generic lambdas
template <typename first>
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
[[nodiscard]]
#elif defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
__attribute__((warn_unused_result))
#endif // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
static inline constexpr decltype(auto)
fix(first &&f) noexcept {
    return [f = std::forward<first>(f)](auto &&... args) {
        return f(f, std::forward<decltype(args)>(args)...);
    };
}

template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll dw[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dh[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793230
#define EPS 1e-7

// 1000000007 で割ったあまりを扱う構造体
class mint {
  public:
    static long long MOD;
    long long val;
    mint(long long v = 0) noexcept : val(v % MOD) {
        if(val < 0) v += MOD;
    }
    int getmod() { return MOD; }
    mint operator-() const noexcept { return val ? MOD - val : 0; }
    mint operator+(const mint &r) const noexcept { return mint(*this) += r; }
    mint operator-(const mint &r) const noexcept { return mint(*this) -= r; }
    mint operator*(const mint &r) const noexcept { return mint(*this) *= r; }
    mint operator/(const mint &r) const noexcept { return mint(*this) /= r; }
    mint &operator+=(const mint &r) noexcept {
        val += r.val;
        val = (val + MOD) % MOD;
        return *this;
    }
    mint &operator-=(const mint &r) noexcept {
        val -= r.val;
        val = (val + MOD) % MOD;
        return *this;
    }
    mint &operator*=(const mint &r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    mint &operator/=(const mint &r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while(b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if(val < 0) val += MOD;
        return *this;
    }
    bool operator==(const mint &r) const noexcept { return this->val == r.val; }
    bool operator!=(const mint &r) const noexcept { return this->val != r.val; }
    friend ostream &operator<<(ostream &os, const mint &x) noexcept {
        return os << x.val;
    }
    friend istream &operator>>(istream &is, mint &x) noexcept {
        return is >> x.val;
    }
    friend mint modpow(const mint &a, long long n) noexcept {
        if(n == 0) return 1;
        mint t = modpow(a, n / 2);
        t = t * t;
        if(n & 1) t = t * a;
        return t;
    }
};
ll mint::MOD = 1e9 + 7;
ll const MAX_SIZE = 1e6 + 1;
mint inv[MAX_SIZE];
mint fact[MAX_SIZE];
mint factinv[MAX_SIZE];
void cominit() {
    inv[1] = 1;
    for(int i = 2; i < MAX_SIZE; i++) {
        inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
    }
    fact[0] = factinv[0] = 1;
    for(int i = 1; i < MAX_SIZE; i++) {
        fact[i] = mint(i) * fact[i - 1];
        factinv[i] = inv[i] * factinv[i - 1];
    }
}
mint comb(int n, int k) {
    if(n >= 0 && k >= 0 && n - k >= 0) {
        return fact[n] * factinv[k] * factinv[n - k];
    }
    return 0;
}
mint hcomb(ll n, ll k) {
    if(n == 0 && k == 0) return 1;
    return comb(n + k - 1, k);
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

void solve() {
    LCIN(N);
    ll ma = 0;
    VL com, os, is;
    REP(i, N) {
        LCIN(out, in);
        os.emplace_back(out);
        is.emplace_back(in);
        com.emplace_back(out);
        com.emplace_back(in);
    }
    sort(All(com));
    com.erase(unique(All(com)), com.end());
    VVL G(sz(com));
    REP(i, N) {
        ll idx = lower_bound(All(com), is[i]) - com.begin();
        ll odx = lower_bound(All(com), os[i]) - com.begin();
        chmax(ma, idx);
        G[idx].emplace_back(odx);
    }
    VL d(sz(com), LINF);
    vector<mint> cnt(sz(com));
    REP(i, sz(com)) {
        ll val = com[i];
        if(d[i] == LINF) {
            d[i] = (i ? d[i - 1] + com[i] - com[i - 1] : com[i]);
            cnt[i] += (i ? cnt[i - 1] : 1);
        }
        FOREACH(to, G[i]) {
            if(d[to] > d[i]) {
                d[to] = d[i];
                cnt[to] = cnt[i];
            } else if(d[to] == d[i]) {
                cnt[to] += cnt[i];
            }
        }
    }
    mint ans = 0;
    FOR(i, ma + 1, sz(com)) { ans += cnt[i]; }
    COUT(ans);
}

signed main() {
    cinfast();
    // cout << fixed << setprecision(12);
    // loop(solve());
    solve();
}


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

typedef long long LL;
typedef pair<int,int> pii;

const int N = 2e5;
const int INF = 1e9+7;
const LL MOD = 1e9+7;

bool cmp(pii a, pii b){
	return a>b;
}

int n;
pii li[N+5];
int memo[N+5];
int ke[N+5];

int cari(int x){
	int l = x+1;
	int r = n;
	int dpt = n+1;
	while(l<=r){
		int mid = (l+r)/2;
		if(li[mid].first <= li[x].second){
			dpt = mid;
			r = mid-1;
		} else {
			l = mid+1;
		}
	}
	return dpt;
}

int dp(int x){
	if(x > n) return 0;
	int &ret = memo[x];
	if(ret!=-1) return ret;
//	ret = dp(x+1) - (li[x].first - li[x+1].first);
	ret = dp(x+1);
	//ambil
	int dpt = ke[x];
	ret = max(ret,dp(dpt)-li[x].second + li[x].first);
	return ret;
}

LL cnt[N+5];

LL bt(int x){
	if(x>n) return 1LL;
	LL &ret = cnt[x];
	if(ret!=-1) return ret;
	ret = 0LL;
	if((dp(x+1)) == dp(x)){
		ret = (ret + bt(x+1))%MOD;
	}
	int dpt = ke[x];
	if(dp(x) == (dp(dpt)-li[x].second + li[x].first)) {
		ret = (ret+bt(dpt))%MOD;
	}
	return ret%MOD;
}

int main(){
	memset(memo,-1,sizeof(memo));
	memset(cnt,-1,sizeof(cnt));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&li[i].first,&li[i].second);
	}
	sort(li+1,li+n+1,cmp);
	for(int i=1;i<=n;i++) ke[i] = cari(i);
	int tar = 2*INF;
	int mini = INF;
	for(int i=1;i<=n;i++){
		if(i >= mini) continue;
		mini = min(mini,ke[i]);
	}
	for(int i=1;i<=n;i++){
		if(i >= mini) continue;
		tar = min(tar,li[i].second - dp(ke[i]));
//		cout << ke[i] << endl;
//		cout << dp(ke[i]) << endl;
	}
	if(tar < 0) assert(0);
	cout << tar << endl;
	LL ans = 0LL;
	for(int i=1;i<=n;i++){
		int tmp = ke[i];
		if((i<mini) && ((li[i].second - dp(ke[i])) == tar)){
			ans = (ans + bt(ke[i]))%MOD;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long LL;
typedef pair<int,int> pii;

const int N = 2e5;
const int INF = 1e9+7;
const LL MOD = 1e9+7;

bool cmp(pii a, pii b){
	return a>b;
}

int n;
pii li[N+5];
int memo[N+5];
int ke[N+5];

int cari(int x){
	int l = x+1;
	int r = n;
	int dpt = n+1;
	while(l<=r){
		int mid = (l+r)/2;
		if(li[mid].first <= li[x].second){
			dpt = mid;
			r = mid-1;
		} else {
			l = mid+1;
		}
	}
	return dpt;
}

int dp(int x){
	if(x > n) return 0;
	int &ret = memo[x];
	if(ret!=-1) return ret;
	ret = dp(x+1) - (li[x].first - li[x+1].first);
	//ambil
	int dpt = ke[x];
	ret = max(ret,dp(dpt)+li[x].second - li[dpt].first);
	return ret;
}

LL cnt[N+5];

LL bt(int x){
	if(x>n) return 1LL;
	LL &ret = cnt[x];
	if(ret!=-1) return ret;
	ret = 0LL;
	if((dp(x+1) - (li[x].first - li[x+1].first)) == dp(x)){
		ret = (ret + bt(x+1))%MOD;
	}
	int dpt = ke[x];
	if(dp(x) == (dp(dpt)+li[x].second - li[dpt].first)) {
		ret = (ret+bt(dpt))%MOD;
	}
	return ret%MOD;
}

int main(){
	memset(memo,-1,sizeof(memo));
	memset(cnt,-1,sizeof(cnt));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&li[i].first,&li[i].second);
	}
	sort(li+1,li+n+1,cmp);
	for(int i=1;i<=n;i++) ke[i] = cari(i);
	int tar = 2*INF;
	int mini = INF;
	for(int i=1;i<=n;i++){
		if(i >= mini) continue;
		mini = min(mini,ke[i]);
	}
	for(int i=1;i<=n;i++){
		if(i >= mini) continue;
		tar = min(tar,li[i].second - dp(ke[i]));
	}
	if(tar < 0) assert(0);
	LL ans = 0LL;
	for(int i=1;i<=n;i++){
		int tmp = ke[i];
		if((i<mini) && ((li[i].second - dp(ke[i])) == tar)){
			ans = (ans + bt(ke[i]))%MOD;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long LL;
typedef pair<int,int> pii;

const int N = 2e5;
const int INF = 1e9+7;
const LL MOD = 1e9+7;

bool cmp(pii a, pii b){
	return a>b;
}

int n;
pii li[N+5];
int memo[N+5];
int ke[N+5];

int cari(int x){
	int l = x+1;
	int r = n;
	int dpt = n+1;
	while(l<=r){
		int mid = (l+r)/2;
		if(li[mid].first <= li[x].second){
			dpt = mid;
			r = mid-1;
		} else {
			l = mid+1;
		}
	}
	return dpt;
}

int dp(int x){
	if(x > n) return 0;
	int &ret = memo[x];
	if(ret!=-1) return ret;
	ret = dp(x+1) - (li[x].first - li[x+1].first);
	//ambil
	int dpt = ke[x];
	ret = max(ret,dp(dpt)+li[x].second - li[dpt].first);
	return ret;
}

LL cnt[N+5];

LL bt(int x){
	if(x>n) return 1LL;
	LL &ret = cnt[x];
	if(ret!=-1) return ret;
	ret = 0LL;
	if((dp(x+1) - (li[x].first - li[x+1].first)) == dp(x)){
		ret = (ret + bt(x+1))%MOD;
	}
	int dpt = ke[x];
	if(dp(x) == (dp(dpt)+li[x].second - li[dpt].first)) {
		ret = (ret+bt(dpt))%MOD;
	}
	return ret%MOD;
}

int main(){
	memset(memo,-1,sizeof(memo));
	memset(cnt,-1,sizeof(cnt));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&li[i].first,&li[i].second);
	}
	sort(li+1,li+n+1,cmp);
	for(int i=1;i<=n;i++) ke[i] = cari(i);
	int tar = 2*INF;
	int mini = INF;
	for(int i=1;i<=n;i++){
		if(i >= mini) continue;
		mini = min(mini,ke[i]);
	}
	for(int i=1;i<=n;i++){
		if(i >= mini) continue;
		tar = min(tar,li[i].second - dp(ke[i]));
	}
	LL ans = 0LL;
	for(int i=1;i<=n;i++){
		int tmp = ke[i];
		if((i<mini) && ((li[i].second - dp(ke[i])) == tar)){
			ans = (ans + bt(ke[i]))%MOD;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long LL;
typedef pair<int,int> pii;

const int N = 2e5;
const int INF = 1e9+7;
const LL MOD = 1e9+7;

bool cmp(pii a, pii b){
	return a>b;
}

int n;
pii li[N+5];
int memo[N+5];
int ke[N+5];

int cari(int x){
	int l = x+1;
	int r = n;
	int dpt = n+1;
	while(l<=r){
		int mid = (l+r)/2;
		if(li[mid].first <= li[x].second){
			dpt = mid;
			r = mid-1;
		} else {
			l = mid+1;
		}
	}
	return dpt;
}

int dp(int x){
	if(x > n) return 0;
	int &ret = memo[x];
	if(ret!=-1) return ret;
//	ret = dp(x+1) - (li[x].first - li[x+1].first);
	ret = dp(x+1);
	//ambil
	int dpt = ke[x];
	ret = max(ret,dp(dpt)-li[x].second + li[x].first);
	return ret;
}

LL cnt[N+5];

LL bt(int x){
	if(x>n) return 1LL;
	LL &ret = cnt[x];
	if(ret!=-1) return ret;
	ret = 0LL;
	if((dp(x+1)) == dp(x)){
		ret = (ret + bt(x+1))%MOD;
	}
	int dpt = ke[x];
	if(dp(x) == (dp(dpt)-li[x].second + li[x].first)) {
		ret = (ret+bt(dpt))%MOD;
	}
	return ret%MOD;
}

int main(){
	memset(memo,-1,sizeof(memo));
	memset(cnt,-1,sizeof(cnt));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&li[i].first,&li[i].second);
	}
	sort(li+1,li+n+1,cmp);
	for(int i=1;i<=n;i++) ke[i] = cari(i);
	int tar = 2*INF;
	int mini = INF;
	for(int i=1;i<=n;i++){
		if(i >= mini) continue;
		mini = min(mini,ke[i]);
	}
	for(int i=1;i<=n;i++){
		if(i >= mini) continue;
		tar = min(tar,li[i].second - dp(ke[i]));
//		cout << ke[i] << endl;
//		cout << dp(ke[i]) << endl;
	}
	if(tar < 0) assert(0);
//	cout << tar << endl;
	LL ans = 0LL;
	for(int i=1;i<=n;i++){
		int tmp = ke[i];
		if((i<mini) && ((li[i].second - dp(ke[i])) == tar)){
			ans = (ans + bt(ke[i]))%MOD;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long LL;
typedef pair<int,int> pii;

const int N = 2e5;
const int INF = 1e9+7;
const LL MOD = 1e9+7;

bool cmp(pii a, pii b){
	return a>b;
}

int n;
pii li[N+5];
int memo[N+5];
int ke[N+5];

int cari(int x){
	int l = x+1;
	int r = n;
	int dpt = n+1;
	while(l<=r){
		int mid = (l+r)/2;
		if(li[mid].first <= li[x].second){
			dpt = mid;
			r = mid-1;
		} else {
			l = mid+1;
		}
	}
	return dpt;
}

int dp(int x){
	if(x > n) return 0;
	int &ret = memo[x];
	if(ret!=-1) return ret;
	ret = dp(x+1) - (li[x].first - li[x+1].first);
	//ambil
	int dpt = ke[x];
	ret = max(ret,dp(dpt)+li[x].second - li[dpt].first);
	return ret;
}

LL cnt[N+5];

LL bt(int x){
	if(x>n) return 1LL;
	LL &ret = cnt[x];
	if(ret!=-1) return ret;
	ret = 0LL;
	if((dp(x+1) - (li[x].first - li[x+1].first)) == dp(x)){
		ret = (ret + bt(x+1))%MOD;
//		cout << "NAMBAH " << bt(x+1) << endl;
	}
	int dpt = ke[x];
	if(dp(x) == (dp(dpt)+li[x].second - li[dpt].first)) {
		ret = (ret+bt(dpt))%MOD;
//		cout << "NAMBAH " << bt(dpt) << endl;
	}
	return ret;
}

int main(){
	memset(memo,-1,sizeof(memo));
	memset(cnt,-1,sizeof(cnt));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&li[i].first,&li[i].second);
	}
	sort(li+1,li+n+1,cmp);
	for(int i=1;i<=n;i++) ke[i] = cari(i);
//	for(int i=1;i<=n;i++){
//		printf("%d : %d %d\n",i,li[i].first,li[i].second);
//		printf("KE : %d\n",ke[i]);
//	}
	int tar = INF;
	int mini = INF;
	for(int i=1;i<=n;i++){
		if(i >= mini) continue;
		mini = min(mini,ke[i]);
		tar = min(tar,li[i].second - dp(ke[i]));
//		cout << i << " LL ";
//		cout << ">> " << dp(ke[i]) << endl;
	}
//	printf("jaja %d\n",tar);
	LL ans = 0LL;
//	for(int i=1;i<=n;i++){
//		cout << "spec " << bt(i) << endl;
//	}
//	for(int i=1;i<=n;i++){
//		cout << "MEMO " << dp(i) << endl;
//	}
	for(int i=1;i<=n;i++){
		int tmp = cari(i);
		if(i<mini && li[i].second - dp(ke[i]) == tar){
//			cout << ">>> " << i << endl;
			ans = (ans + bt(ke[i]))%MOD;
//			cout << ">>> " << bt(ke[i]) << endl;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long LL;
typedef pair<int,int> pii;

const int N = 2e5;
const int INF = 1e9+7;
const LL MOD = 1e9+7;

bool cmp(pii a, pii b){
	return a>b;
}

int n;
pii li[N+5];
int memo[N+5];
int ke[N+5];

int cari(int x){
	int l = x+1;
	int r = n;
	int dpt = n+1;
	while(l<=r){
		int mid = (l+r)/2;
		if(li[mid].first <= li[x].second){
			dpt = mid;
			r = mid-1;
		} else {
			l = mid+1;
		}
	}
	return dpt;
}

int dp(int x){
	if(x > n) return 0;
	int &ret = memo[x];
	if(ret!=-1) return ret;
	ret = dp(x+1) - (li[x].first - li[x+1].first);
	//ambil
	int dpt = ke[x];
	ret = max(ret,dp(dpt)+li[x].second - li[dpt].first);
	return ret;
}

LL cnt[N+5];

LL bt(int x){
	if(x>n) return 1LL;
	LL &ret = cnt[x];
	if(ret!=-1) return ret;
	ret = 0LL;
	if((dp(x+1) - (li[x].first - li[x+1].first)) == dp(x)){
		ret = (ret + bt(x+1))%MOD;
//		cout << "NAMBAH " << bt(x+1) << endl;
	}
	int dpt = ke[x];
	if(dp(x) == (dp(dpt)+li[x].second - li[dpt].first)) {
		ret = (ret+bt(dpt))%MOD;
//		cout << "NAMBAH " << bt(dpt) << endl;
	}
	return ret;
}

int main(){
	memset(memo,-1,sizeof(memo));
	memset(cnt,-1,sizeof(cnt));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&li[i].first,&li[i].second);
	}
	sort(li+1,li+n+1,cmp);
	for(int i=1;i<=n;i++) ke[i] = cari(i);
//	for(int i=1;i<=n;i++){
//		printf("%d : %d %d\n",i,li[i].first,li[i].second);
//		printf("KE : %d\n",ke[i]);
//	}
	int tar = INF;
	int mini = INF;
	for(int i=1;i<=n;i++){
		if(i >= mini) continue;
		mini = min(mini,ke[i]);
//		tar = min(tar,li[i].second - dp(ke[i]));
	}
	for(int i=1;i<=n;i++){
		if(i >= mini) continue;
		tar = min(tar,li[i].second - dp(ke[i]));
	}
	LL ans = 0LL;
	for(int i=1;i<=n;i++){
		int tmp = cari(i);
		if(i<mini && li[i].second - dp(ke[i]) == tar){
//			cout << ">>> " << i << endl;
			ans = (ans + bt(ke[i]))%MOD;
//			cout << ">>> " << bt(ke[i]) << endl;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;
typedef pair < ll , ll > pll;

const double PI = acos(-1);
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const ll INF = 1e15;

ll addMod(ll a, ll b){
	if(a + b >= MOD) return a + b - MOD;
	return a + b;
}

ll mulMod(ll a, ll b){
	return (a*b)%MOD;
}

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp,tmp);
	if(b & 1) tmp = mulMod(tmp,a);
	return tmp;
}

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

//////////////////////////////////////////////

const int N = 2e5;

struct datt{
	int in, out;
};

datt dat[N + 5];
pll tree[4*N + 5];
int n;

bool cmp(datt a, datt b){
	return a.in < b.in;
}

int idxMN(int id, ll mn){
	int l = id+1, r = n, mid, ret = n+1;
	while(l <= r){
		mid = (l + r) / 2;
		if(dat[mid].in >= mn){
			r = mid - 1;
			ret = mid;
		}
		else{
			l = mid + 1;
		}
	}
	return ret;
}

void update(int idx, int l, int r, int a, pll v){
	if(l == r){
		tree[idx] = v;
		return;
	}
	int mid = (l + r) / 2;
	if(a <= mid) update(idx*2,l,mid,a,v);
	else update(idx*2+1,mid+1,r,a,v);
	pll lt = tree[idx*2];
	pll rt = tree[idx*2+1];
	if(lt.FI < rt.FI) tree[idx] = lt;
	else if(lt.FI > rt.FI) tree[idx] = rt;
	else tree[idx] = MP(lt.FI, addMod(lt.SE,rt.SE));
}

pll query(int idx, int l, int r, int a, int b){
	if(l >= a && r <= b) return tree[idx];
	if(l > b || r < a) return MP(INF,0);
	int mid = (l + r) / 2;
	pll lt = query(idx*2,l,mid,a,b);
	pll rt = query(idx*2+1,mid+1,r,a,b);
	if(lt.FI < rt.FI) return lt;
	else if(lt.FI > rt.FI) return rt;
	else return MP(lt.FI, addMod(lt.SE, rt.SE));
}

ll solve(){
	sort(dat+1,dat+n+1,cmp);
	REP(i,1,n){
		update(1,1,n,i,MP(dat[i].in,1));
	}
	REV(i,n,1){
		int idx = idxMN(i,dat[i].out);
		if(idx == n+1) continue;
		pll val = query(1,1,n,idx,n);
		update(1,1,n,i,MP(val.FI - dat[i].out + dat[i].in, val.SE));
	}
	return query(1,1,n,1,n).SE;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	REP(i,1,n) cin >> dat[i].out >> dat[i].in;
	cout << solve() << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;
typedef pair < ll , ll > pll;

const double PI = acos(-1);
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const ll INF = 1e15;

ll addMod(ll a, ll b){
	if(a + b >= MOD) return a + b - MOD;
	return a + b;
}

ll mulMod(ll a, ll b){
	return (a*b)%MOD;
}

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp,tmp);
	if(b & 1) tmp = mulMod(tmp,a);
	return tmp;
}

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

//////////////////////////////////////////////

const int N = 2e5;

struct datt{
	int in, out;
};

datt dat[N + 5];
pll tree[N + 5];
int n;

bool cmp(datt a, datt b){
	return a.in < b.in;
}

int idxMN(int id, ll mn){
	int l = id+1, r = n, mid, ret = n+1;
	while(l <= r){
		mid = (l + r) / 2;
		if(dat[mid].in >= mn){
			r = mid - 1;
			ret = mid;
		}
		else{
			l = mid + 1;
		}
	}
	return ret;
}

void update(int idx, int l, int r, int a, pll v){
	if(l == r){
		tree[idx] = v;
		return;
	}
	int mid = (l + r) / 2;
	if(a <= mid) update(idx*2,l,mid,a,v);
	else update(idx*2+1,mid+1,r,a,v);
	pll lt = tree[idx*2];
	pll rt = tree[idx*2+1];
	if(lt.FI < rt.FI) tree[idx] = lt;
	else if(lt.FI > rt.FI) tree[idx] = rt;
	else tree[idx] = MP(lt.FI, addMod(lt.SE,rt.SE));
}

pll query(int idx, int l, int r, int a, int b){
	if(l >= a && r <= b) return tree[idx];
	if(l > b || r < a) return MP(INF,0);
	int mid = (l + r) / 2;
	pll lt = query(idx*2,l,mid,a,b);
	pll rt = query(idx*2+1,mid+1,r,a,b);
	if(lt.FI < rt.FI) return lt;
	else if(lt.FI > rt.FI) return rt;
	else return MP(lt.FI, addMod(lt.SE, rt.SE));
}

ll solve(){
	sort(dat+1,dat+n+1,cmp);
	REP(i,1,n){
		update(1,1,n,i,MP(dat[i].in,1));
	}
	REV(i,n,1){
		int idx = idxMN(i,dat[i].out);
		if(idx == n+1) continue;
		pll val = query(1,1,n,idx,n);
		update(1,1,n,i,MP(val.FI - dat[i].out + dat[i].in, val.SE));
	}
	return query(1,1,n,1,n).SE;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	REP(i,1,n) cin >> dat[i].out >> dat[i].in;
	cout << solve() << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;
typedef pair < ll , ll > pll;

const double PI = acos(-1);
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const int INF = 1e9;

ll addMod(ll a, ll b){
	if(a + b >= MOD) return a + b - MOD;
	return a + b;
}

ll mulMod(ll a, ll b){
	return (a*b)%MOD;
}

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp,tmp);
	if(b & 1) tmp = mulMod(tmp,a);
	return tmp;
}

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

//////////////////////////////////////////////

const int N = 2e5;

struct datt{
	int in, out;
};

datt dat[N + 5];
pll tree[N + 5];
int n;

bool cmp(datt a, datt b){
	return a.in < b.in;
}

int idxMN(int id, ll mn){
	int l = id+1, r = n, mid, ret = n+1;
	while(l <= r){
		mid = (l + r) / 2;
		if(dat[mid].in >= mn){
			r = mid - 1;
			ret = mid;
		}
		else{
			l = mid + 1;
		}
	}
	return ret;
}

void update(int idx, int l, int r, int a, pll v){
	if(l == r){
		tree[idx] = v;
		return;
	}
	int mid = (l + r) / 2;
	if(a <= mid) update(idx*2,l,mid,a,v);
	else update(idx*2+1,mid+1,r,a,v);
	pll lt = tree[idx*2];
	pll rt = tree[idx*2+1];
	if(lt.FI < rt.FI) tree[idx] = lt;
	else if(lt.FI > rt.FI) tree[idx] = rt;
	else tree[idx] = MP(lt.FI, lt.SE + rt.SE);
}

pll query(int idx, int l, int r, int a, int b){
	if(l >= a && r <= b) return tree[idx];
	if(l > b || r < a) return MP(INF,0);
	int mid = (l + r) / 2;
	pll lt = query(idx*2,l,mid,a,b);
	pll rt = query(idx*2+1,mid+1,r,a,b);
	if(lt.FI < rt.FI) return lt;
	else if(lt.FI > rt.FI) return rt;
	else return MP(lt.FI, lt.SE + rt.SE);
}

ll solve(){
	sort(dat+1,dat+n+1,cmp);
	REP(i,1,n){
		update(1,1,n,i,MP(dat[i].in,1));
	}
	REV(i,n,1){
		int idx = idxMN(i,dat[i].out);
		if(idx == n+1) continue;
		pll val = query(1,1,n,idx,n);
		update(1,1,n,i,MP(val.FI - dat[i].out + dat[i].in, val.SE));
	}
	return query(1,1,n,1,n).SE;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	REP(i,1,n) cin >> dat[i].out >> dat[i].in;
	cout << solve() << endl;
	return 0;
}


/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/
#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
//# define DEBUG
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define pii pair<ll,ll>
# define inf (ll)1e9
# define mx2 1000005
# define mx 100005
//# define endl "\n"
pii tree[4*mx+1],dp[mx];
ll lo[4*mx+1],hi[4*mx+1],out[mx],in[mx];
void init(ll i,ll a,ll b)
{
	lo[i]=a;
	hi[i]=b;
	if(a==b)
		return;
	ll m=(a+b)/2;
	init(2*i,a,m);
	init(2*i+1,m+1,b);
}
pii merge(pii i1,pii i2)
{
	if(i1.ff==i2.ff)
		return {i1.ff,i1.ss+i2.ss};
	else if(i1.ff>i2.ff)
		return i2;
	else
		return i1;
}
void build(ll i)
{
	ll l=lo[i];
	ll r=hi[i];
	if(l==r)
	{
		tree[i]={in[l-1],1};
		return;
	}
	build(2*i);
	build(2*i+1);
	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
void update(ll i,ll pos,pii val) // last doll was i and minimum space
{
	ll l=lo[i];
	ll r=hi[i];
	if(lo[i]==hi[i] && lo[i]==pos)
	{
		tree[i]=val;
		return;
	}
	ll m=(l+r)/2;
	if(pos<=m)
		update(2*i,pos,val);
	else
		update(2*i+1,pos,val);

	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
pii query(ll i,ll l,ll r)
{
	if(r<lo[i] || hi[i]<l)
	{
		return {inf,1};
	}
	if(l<=lo[i] && hi[i]<=r)
	{
		return tree[i];
	}
	return merge(query(2*i,l,r),query(2*i+1,l,r));

}
int main()
{
	//IOS;
	ll n;
	cin>>n;
	vector <pii> vec;
	for(ll i=0;i<n;i++)
	{
		cin>>out[i]>>in[i];
		vec.pb({in[i],out[i]});
	}
	sort(in,in+n);
	sort(vec.begin(),vec.end());
	#ifdef DEBUG
	for(auto k:vec)
		cout<<k.ff<<" "<<k.ss<<endl;
	#endif
	init(1,1,n);
	build(1);
	pii final={inf,1};
	for(ll i=n-1;i>=0;i--)
	{
		ll it=lower_bound(in,in+n,vec[i].ss)-in;
		if(it==n)continue;
		pii q=query(1,it+1,n);
		q.ff+=vec[i].ff-vec[i].ss;
		#ifdef DEBUG
		cout<<it<<" "<<q.ff<<" "<<q.ss<<endl;
		#endif
		update(1,i+1,q);
		if(q.ff<final.ff)
			final=q;
		else if(q.ff==final.ff)
			final.ss+=q.ss;
	}
	cout<<final.ss<<endl;
}


/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/

#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
//# define DEBUG
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define pii pair<ll,ll>
# define inf (ll)1e9
# define mx2 1000005
# define mx 200005
//# define endl "\n"
pii tree[4*mx+1],dp[mx];
ll lo[4*mx+1],hi[4*mx+1],out[mx],in[mx];
void init(ll i,ll a,ll b)
{
	lo[i]=a;
	hi[i]=b;
	if(a==b)
		return;
	ll m=(a+b)/2;
	init(2*i,a,m);
	init(2*i+1,m+1,b);
}
pii merge(pii i1,pii i2)
{
	if(i1.ff==i2.ff)
		return {i1.ff,(i1.ss+i2.ss)%mod};
	else if(i1.ff>i2.ff)
		return i2;
	else
		return i1;
}
void build(ll i)
{
	ll l=lo[i];
	ll r=hi[i];
	if(l==r)
	{
		tree[i]={in[l-1],1};
		return;
	}
	build(2*i);
	build(2*i+1);
	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
void update(ll i,ll pos,pii val) // last doll was i and minimum space
{
	ll l=lo[i];
	ll r=hi[i];
	if(lo[i]==hi[i] && lo[i]==pos)
	{
		tree[i]=val;
		return;
	}
	ll m=(l+r)/2;
	if(pos<=m)
		update(2*i,pos,val);
	else
		update(2*i+1,pos,val);

	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
pii query(ll i,ll l,ll r)
{
	if(r<lo[i] || hi[i]<l)
	{
		return {inf,1};
	}
	if(l<=lo[i] && hi[i]<=r)
	{
		return tree[i];
	}
	return merge(query(2*i,l,r),query(2*i+1,l,r));

}
int main()
{
	//IOS;
	ll n;
	cin>>n;
	vector <pii> vec;
	for(ll i=0;i<n;i++)
	{
		cin>>out[i]>>in[i];
		vec.pb({in[i],out[i]});
	}
	sort(in,in+n);
	sort(vec.begin(),vec.end());
	#ifdef DEBUG
	for(auto k:vec)
		cout<<k.ff<<" "<<k.ss<<endl;
	#endif
	init(1,1,n);
	build(1);
	pii final={inf,0};
	for(ll i=n-1;i>=0;i--)
	{
		ll it=lower_bound(in,in+n,vec[i].ss)-in;
		if(it==n)
		{
			if(final.ff>in[i])
				final={in[i],1};
			else if(final.ff==in[i])
				final.ss++;
			continue;
		}
		pii q=query(1,it+1,n);
		q.ff+=vec[i].ff-vec[i].ss;
		#ifdef DEBUG
		cout<<it<<" "<<q.ff<<" "<<q.ss<<endl;
		#endif
		update(1,i+1,q);
		if(q.ff<final.ff)
			final=q;
		else if(q.ff==final.ff)
			{final.ss+=q.ss;final.ss%=mod;}
	}
	cout<<final.ss<<endl;
}


/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/
#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
//# define DEBUG
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define pii pair<ll,ll>
# define inf (ll)1e9
# define mx2 1000005
# define mx 100005
//# define endl "\n"
pii tree[4*mx+1],dp[mx];
ll lo[4*mx+1],hi[4*mx+1],out[mx],in[mx];
void init(ll i,ll a,ll b)
{
	lo[i]=a;
	hi[i]=b;
	if(a==b)
		return;
	ll m=(a+b)/2;
	init(2*i,a,m);
	init(2*i+1,m+1,b);
}
pii merge(pii i1,pii i2)
{
	if(i1.ff==i2.ff)
		return {i1.ff,i1.ss+i2.ss};
	else if(i1.ff>i2.ff)
		return i2;
	else
		return i1;
}
void build(ll i)
{
	ll l=lo[i];
	ll r=hi[i];
	if(l==r)
	{
		tree[i]={in[l-1],1};
		return;
	}
	build(2*i);
	build(2*i+1);
	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
void update(ll i,ll pos,pii val) // last doll was i and minimum space
{
	ll l=lo[i];
	ll r=hi[i];
	if(lo[i]==hi[i] && lo[i]==pos)
	{
		tree[i]=val;
		return;
	}
	ll m=(l+r)/2;
	if(pos<=m)
		update(2*i,pos,val);
	else
		update(2*i+1,pos,val);

	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
pii query(ll i,ll l,ll r)
{
	if(r<lo[i] || hi[i]<l)
	{
		return {ll_MAX,1};
	}
	if(l<=lo[i] && hi[i]<=r)
	{
		return tree[i];
	}
	return merge(query(2*i,l,r),query(2*i+1,l,r));

}
int main()
{
	//IOS;
	ll n;
	cin>>n;
	vector <pii> vec;
	for(ll i=0;i<n;i++)
	{
		cin>>out[i]>>in[i];
		vec.pb({in[i],out[i]});
	}
	sort(in,in+n);
	sort(vec.begin(),vec.end());
	#ifdef DEBUG
	for(auto k:vec)
		cout<<k.ff<<" "<<k.ss<<endl;
	#endif
	init(1,1,n);
	build(1);
	pii final={inf,0};
	for(ll i=n-1;i>=0;i--)
	{
		ll it=lower_bound(in,in+n,vec[i].ss)-in;
		if(it==n)continue;
		pii q=query(1,it+1,n);
		q.ff+=vec[i].ff-vec[i].ss;
		#ifdef DEBUG
		cout<<it<<" "<<q.ff<<" "<<q.ss<<endl;
		#endif
		update(1,i+1,q);
		if(q.ff<final.ff)
			final=q;
		else if(q.ff==final.ff)
			final.ss+=q.ss;
	}
	cout<<final.ss<<endl;
}


/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/
#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
//# define DEBUG
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define pii pair<ll,ll>
# define inf (ll)1e9
# define mx2 1000005
# define mx 100005
//# define endl "\n"
pii tree[4*mx+1],dp[mx];
ll lo[4*mx+1],hi[4*mx+1],out[mx],in[mx];
void init(ll i,ll a,ll b)
{
	lo[i]=a;
	hi[i]=b;
	if(a==b)
		return;
	ll m=(a+b)/2;
	init(2*i,a,m);
	init(2*i+1,m+1,b);
}
pii merge(pii i1,pii i2)
{
	if(i1.ff==i2.ff)
		return {i1.ff,i1.ss+i2.ss};
	else if(i1.ff>i2.ff)
		return i2;
	else
		return i1;
}
void build(ll i)
{
	ll l=lo[i];
	ll r=hi[i];
	if(l==r)
	{
		tree[i]={in[l-1],1};
		return;
	}
	build(2*i);
	build(2*i+1);
	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
void update(ll i,ll pos,pii val) // last doll was i and minimum space
{
	ll l=lo[i];
	ll r=hi[i];
	if(lo[i]==hi[i] && lo[i]==pos)
	{
		tree[i]=val;
		return;
	}
	ll m=(l+r)/2;
	if(pos<=m)
		update(2*i,pos,val);
	else
		update(2*i+1,pos,val);

	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
pii query(ll i,ll l,ll r)
{
	if(r<lo[i] || hi[i]<l)
	{
		return {inf,1};
	}
	if(l<=lo[i] && hi[i]<=r)
	{
		return tree[i];
	}
	return merge(query(2*i,l,r),query(2*i+1,l,r));

}
int main()
{
	//IOS;
	ll n;
	cin>>n;
	vector <pii> vec;
	for(ll i=0;i<n;i++)
	{
		cin>>out[i]>>in[i];
		vec.pb({in[i],out[i]});
	}
	sort(in,in+n);
	sort(vec.begin(),vec.end());
	#ifdef DEBUG
	for(auto k:vec)
		cout<<k.ff<<" "<<k.ss<<endl;
	#endif
	init(1,1,n);
	build(1);
	pii final={inf,0};
	for(ll i=n-1;i>=0;i--)
	{
		ll it=lower_bound(in,in+n,vec[i].ss)-in;
		if(it==n)continue;
		pii q=query(1,it+1,n);
		q.ff+=vec[i].ff-vec[i].ss;
		#ifdef DEBUG
		cout<<it<<" "<<q.ff<<" "<<q.ss<<endl;
		#endif
		update(1,i+1,q);
		if(q.ff<final.ff)
			final=q;
		else if(q.ff==final.ff)
			final.ss+=q.ss;
	}
	cout<<final.ss<<endl;
}


/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/
#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
//# define DEBUG
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define pii pair<ll,ll>
# define inf (ll)1e9
# define mx2 1000005
# define mx 200005
//# define endl "\n"
pii tree[4*mx+1],dp[mx];
ll lo[4*mx+1],hi[4*mx+1],out[mx],in[mx];
void init(ll i,ll a,ll b)
{
	lo[i]=a;
	hi[i]=b;
	if(a==b)
		return;
	ll m=(a+b)/2;
	init(2*i,a,m);
	init(2*i+1,m+1,b);
}
pii merge(pii i1,pii i2)
{
	if(i1.ff==i2.ff)
		return {i1.ff,(i1.ss+i2.ss)%mod};
	else if(i1.ff>i2.ff)
		return i2;
	else
		return i1;
}
void build(ll i)
{
	ll l=lo[i];
	ll r=hi[i];
	if(l==r)
	{
		tree[i]={in[l-1],1};
		return;
	}
	build(2*i);
	build(2*i+1);
	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
void update(ll i,ll pos,pii val) // last doll was i and minimum space
{
	ll l=lo[i];
	ll r=hi[i];
	if(lo[i]==hi[i] && lo[i]==pos)
	{
		tree[i]=val;
		return;
	}
	ll m=(l+r)/2;
	if(pos<=m)
		update(2*i,pos,val);
	else
		update(2*i+1,pos,val);

	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
pii query(ll i,ll l,ll r)
{
	if(r<lo[i] || hi[i]<l)
	{
		return {inf,1};
	}
	if(l<=lo[i] && hi[i]<=r)
	{
		return tree[i];
	}
	return merge(query(2*i,l,r),query(2*i+1,l,r));

}
int main()
{
	//IOS;
	ll n;
	cin>>n;
	vector <pii> vec;
	for(ll i=0;i<n;i++)
	{
		cin>>out[i]>>in[i];
		vec.pb({in[i],out[i]});
	}
	sort(in,in+n);
	sort(vec.begin(),vec.end());
	#ifdef DEBUG
	for(auto k:vec)
		cout<<k.ff<<" "<<k.ss<<endl;
	#endif
	init(1,1,n);
	build(1);
	pii final={inf,0};
	for(ll i=n-1;i>=0;i--)
	{
		ll it=lower_bound(in,in+n,vec[i].ss)-in;
		if(it==n)
		{
			if(final.ff>in[i])
				final={in[i],1};
			else if(final.ff==in[i])
				final.ss++;
			continue;
		}
		pii q=query(1,it+1,n);
		q.ff+=vec[i].ff-vec[i].ss;
		#ifdef DEBUG
		cout<<it<<" "<<q.ff<<" "<<q.ss<<endl;
		#endif
		update(1,i+1,q);
		if(q.ff<final.ff)
			final=q;
		else if(q.ff==final.ff)
			{final.ss+=q.ss;final.ss%=mod;}
	}
	cout<<final.ss<<endl;
}


/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/
#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
//# define DEBUG
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define pii pair<ll,ll>
# define inf (ll)1e9
# define mx2 1000005
# define mx 200005
//# define endl "\n"
pii tree[4*mx+1],dp[mx];
ll lo[4*mx+1],hi[4*mx+1],out[mx],in[mx];
void init(ll i,ll a,ll b)
{
	lo[i]=a;
	hi[i]=b;
	if(a==b)
		return;
	ll m=(a+b)/2;
	init(2*i,a,m);
	init(2*i+1,m+1,b);
}
pii merge(pii i1,pii i2)
{
	if(i1.ff==i2.ff)
		return {i1.ff,(i1.ss+i2.ss)%mod};
	else if(i1.ff>i2.ff)
		return i2;
	else
		return i1;
}
void build(ll i)
{
	ll l=lo[i];
	ll r=hi[i];
	if(l==r)
	{
		tree[i]={in[l-1],1};
		return;
	}
	build(2*i);
	build(2*i+1);
	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
void update(ll i,ll pos,pii val) // last doll was i and minimum space
{
	ll l=lo[i];
	ll r=hi[i];
	if(lo[i]==hi[i] && lo[i]==pos)
	{
		tree[i]=val;
		return;
	}
	ll m=(l+r)/2;
	if(pos<=m)
		update(2*i,pos,val);
	else
		update(2*i+1,pos,val);

	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
pii query(ll i,ll l,ll r)
{
	if(r<lo[i] || hi[i]<l)
	{
		return {inf,1};
	}
	if(l<=lo[i] && hi[i]<=r)
	{
		return tree[i];
	}
	return merge(query(2*i,l,r),query(2*i+1,l,r));

}
int main()
{
	//IOS;
	ll n;
	cin>>n;
	vector <pii> vec;
	for(ll i=0;i<n;i++)
	{
		cin>>out[i]>>in[i];
		vec.pb({in[i],out[i]});
	}
	sort(in,in+n);
	sort(vec.begin(),vec.end());
	#ifdef DEBUG
	for(auto k:vec)
		cout<<k.ff<<" "<<k.ss<<endl;
	#endif
	init(1,1,n);
	build(1);
	pii final={inf,1};
	for(ll i=n-1;i>=0;i--)
	{
		ll it=lower_bound(in,in+n,vec[i].ss)-in;
		if(it==n)continue;
		pii q=query(1,it+1,n);
		q.ff+=vec[i].ff-vec[i].ss;
		#ifdef DEBUG
		cout<<it<<" "<<q.ff<<" "<<q.ss<<endl;
		#endif
		update(1,i+1,q);
		if(q.ff<final.ff)
			final=q;
		else if(q.ff==final.ff)
			{final.ss+=q.ss;final.ss%=mod;}
	}
	cout<<final.ss<<endl;
}


/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/
#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
//# define DEBUG
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define pii pair<ll,ll>
# define inf (ll)1e9
# define mx2 1000005
# define mx 200005
//# define endl "\n"
pii tree[4*mx+1],dp[mx];
ll lo[4*mx+1],hi[4*mx+1],out[mx],in[mx];
void init(ll i,ll a,ll b)
{
	lo[i]=a;
	hi[i]=b;
	if(a==b)
		return;
	ll m=(a+b)/2;
	init(2*i,a,m);
	init(2*i+1,m+1,b);
}
pii merge(pii i1,pii i2)
{
	if(i1.ff==i2.ff)
		return {i1.ff,i1.ss+i2.ss};
	else if(i1.ff>i2.ff)
		return i2;
	else
		return i1;
}
void build(ll i)
{
	ll l=lo[i];
	ll r=hi[i];
	if(l==r)
	{
		tree[i]={in[l-1],1};
		return;
	}
	build(2*i);
	build(2*i+1);
	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
void update(ll i,ll pos,pii val) // last doll was i and minimum space
{
	ll l=lo[i];
	ll r=hi[i];
	if(lo[i]==hi[i] && lo[i]==pos)
	{
		tree[i]=val;
		return;
	}
	ll m=(l+r)/2;
	if(pos<=m)
		update(2*i,pos,val);
	else
		update(2*i+1,pos,val);

	tree[i]=merge(tree[2*i],tree[2*i+1]);
}
pii query(ll i,ll l,ll r)
{
	if(r<lo[i] || hi[i]<l)
	{
		return {inf,1};
	}
	if(l<=lo[i] && hi[i]<=r)
	{
		return tree[i];
	}
	return merge(query(2*i,l,r),query(2*i+1,l,r));

}
int main()
{
	//IOS;
	ll n;
	cin>>n;
	vector <pii> vec;
	for(ll i=0;i<n;i++)
	{
		cin>>out[i]>>in[i];
		vec.pb({in[i],out[i]});
	}
	sort(in,in+n);
	sort(vec.begin(),vec.end());
	#ifdef DEBUG
	for(auto k:vec)
		cout<<k.ff<<" "<<k.ss<<endl;
	#endif
	init(1,1,n);
	build(1);
	pii final={inf,1};
	for(ll i=n-1;i>=0;i--)
	{
		ll it=lower_bound(in,in+n,vec[i].ss)-in;
		if(it==n)continue;
		pii q=query(1,it+1,n);
		q.ff+=vec[i].ff-vec[i].ss;
		#ifdef DEBUG
		cout<<it<<" "<<q.ff<<" "<<q.ss<<endl;
		#endif
		update(1,i+1,q);
		if(q.ff<final.ff)
			final=q;
		else if(q.ff==final.ff)
			final.ss+=q.ss;
	}
	cout<<final.ss<<endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

const long long MOD = 1e9 + 7;
long long n, mxe, cur, ans, le, l, r, mid, mx[300005], cnt[300005], mn = 0x3f3f3f3f3f3f3f3f, me = 0x3f3f3f3f;
pair <long long, long long> a[300005];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		mxe = max(mxe, (long long) a[i].fi);
		me = min(me, (long long) a[i].fi);
		le = max(le, (long long) a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n + 1, 0x3f3f3f3f3f3f3f3f);
	for (int i = n - 1; i >= 0; i--) {
//		cout << a[i].fi << ' ' << a[i].se << endl;
		if (a[i].fi > le) mx[i] = 0, cnt[i] = 1;
		if (mx[i] > mx[i + 1] + a[i + 1].fi - a[i].fi){
			mx[i] = mx[i + 1] + a[i + 1].fi - a[i].fi;
			cnt[i] = cnt[i + 1];
		}
		else if (mx[i] == mx[i + 1] + a[i + 1].fi - a[i].fi && cnt[i] != 0) cnt[i] = (cnt[i] + cnt[i + 1]) % MOD;
		l = 0, r = i - 1;
		while (l < r) {
			mid = (l + r + 1) / 2;
			if (a[i].se < a[mid].fi) r = mid - 1;
			else l = mid;
		}
//		cout << l << endl;
		if (a[i].se >= a[l].fi) {
			if (mx[l] > mx[i] + a[i].se - a[l].fi) {
				mx[l] = mx[i] + a[i].se - a[l].fi;
				cnt[l] = cnt[i];
			}
			else if (mx[l] == mx[i] + a[i].se - a[l].fi) cnt[l] = (cnt[l] + cnt[i]) % MOD;
		}
		if (a[i].se < me) {
			if (mx[i] + a[i].se < mn) {
				mn = mx[i] + a[i].se;
				ans = cnt[i];
			}
			else if (mx[i] + a[i].se == mn) ans = (ans + cnt[i]) % MOD;
		}
//		cout << mx[i] << ' ' << cnt[i] << endl;
	}
	cout << ans << endl;
}