#include <fstream>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
    ifstream cin("castle.in");
    ofstream cout("castle.out");
    int n, s;
    long long res = 0;
    cin >> n >> s;
    pair <int, int> a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i].second >> a[i].first;
        res += a[i].second;
    }
    //cout << "res = " << res << endl;
    sort(a, a + n, greater<pair<int,int> >());
    int cur;
    priority_queue <int> lefts;
    for (int i = 0; i < n; i++) {
        while (!lefts.empty() && lefts.top() > a[i].first && s > 0) {
            s--;
            res -= lefts.top();
            //cout << "set " << lefts.top() << endl;
            lefts.pop();
        }
        cur = min(s, a[i].second / a[i].first);
        //cout << "put " << cur << " on " << a[i].second << " by " << a[i].first << endl;
        s -= cur;
        a[i].second -= cur * a[i].first;

    //cout << "res -= " << cur * a[i].first << endl;
        res -= cur * a[i].first;
        if (a[i].second < a[i].first && a[i].second != 0)
            lefts.push(a[i].second);

    }
        while (!lefts.empty()  && s > 0) {
            s--;

            //cout << "bet " << *(lefts.rbegin()) << endl;
            res -= lefts.top();
            lefts.pop();
        }
    cout << res;
    return 0;
}
