#include <fstream>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

int main(){
    ifstream fin("castle.in");
    ofstream fout("castle.out");
    long long n, s, summ = 0;

    fin >> n >> s;

    vector< pair<long long, long long> > mas(n);

    for(long long i = 0; i < n; ++i){
        fin >> mas[i].second >> mas[i].first;
        summ += mas[i].second;
    }

    sort(mas.rbegin(), mas.rend());

    long long i = 0, cur;

    vector<long long> mas2;

    while (i < n && s > 0){
        if (mas[i].second < mas[i].first){
            if (i == n - 1){
                mas2.push_back(mas[i].second);
            }
            else if (mas[i].second > mas[i + 1].first){
                s--;
                summ -= mas[i].second;
                mas[i].second = 0;
            }
            else{
                mas2.push_back(mas[i].second);
            }

            ++i;
        }
        else{
            cur = min(s, mas[i].second / mas[i].first);
            s -= cur;
            summ -= mas[i].first * cur;
            mas[i].second -= mas[i].first * cur;
        }
    }

    if (s > 0){
        sort(mas2.begin(), mas2.end());

        i = 0;
        while (i < mas2.size() && s > 0){
            s--;
            summ -= mas2[i];
            ++i;
        }
    }

    fout << summ << endl;

    fin.close();
    fout.close();
    return 0;
}
