#include <bits/stdc++.h>

using namespace std;
/*
bool comp(pair<int, int> lhs, pair<int, int> rhs){
    return lhs.second
}
*/
void secA(){
    int n, s;
    cin >> n >> s;
    pair<int, int> p[n];
    for(int i = 0; i < n; ++i){
        cin >> p[i].second >> p[i].first;
    }
    multiset<int> obrezki;
    sort(p, p + n);
    long long ans = 0;
    for(int i = n - 1; i >= 0; --i){
       // cerr << "CYCLE1\n";
       //cerr << *obrezki.begin() << endl;
            while(s > 0 && !obrezki.empty() && *obrezki.begin() >= p[i].first){
                --s;
                obrezki.erase(obrezki.begin());
            }
        if(s > 0 && s >= p[i].second / p[i].first){
            s -= (p[i].second / p[i].first);
            p[i].second -= p[i].first * (p[i].second / p[i].first);
            obrezki.insert(-p[i].second);
        }
        else{
            if(s > 0){
                p[i].second -= s * p[i].first;
                s = 0;
            }
            obrezki.insert(-p[i].second);
        }
    }
    while(s > 0 && !obrezki.empty()){
        obrezki.erase(obrezki.begin());
        --s;
    }
    while(!obrezki.empty()){
        ans -= *obrezki.begin();
        obrezki.erase(obrezki.begin());
    }
   // cerr << ans << endl;
    cout << ans << endl;
    return ;

}

void solvea(){
    int n, s;
    cin >> n >> s;
    pair<int, int> p[n];
    for(int i = 0; i < n; ++i){
        cin >> p[i].second >> p[i].first;
    }
    sort(p, p + n);
    long long ans = 0;
    for(int i = n - 1; i >= 0; --i){
//        cerr << p[i].first << ' ' << p[i].second << endl;
//        cerr << (p[i].second / p[i].first) << endl;

        if(s >= p[i].second / p[i].first){
            s -= (p[i].second / p[i].first);
            p[i].second -= p[i].first * (p[i].second / p[i].first);
            swap(p[i].first, p[i].second);
            if(s > 0 && i > 0 && p[i].first > p[i - 1].first){
                p[i].first = 0;
                --s;
            }
        }
        else{
            if(s > 0){
                p[i].second -= p[i].first * s;
                s = 0;
                swap(p[i].first, p[i].second);
            }
            else
                swap(p[i].first, p[i].second);
        }
    }
    sort(p, p + n);
    int u = n - 1;
    while(s > 0){
        --u;
        --s;
    }
    for(;u >= 0; --u){
        ans += p[u].first;
    }
    cout << ans << endl;
    return ;
}

int main(){
    freopen("castle.in","r",stdin);
    freopen("castle.out","w",stdout);
    secA();
    return 0;
}
