#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <set>
using namespace std;

vector <int> a;
vector <int> k;
long long ans;
long long can;
int n;
class comp
{
public:
    bool operator()(int c, int b)
    {
        int _c = min(a[c], k[c]);
        int _b = min(a[b], k[b]);
        if (_c > _b)
            return 1;
        else
            return 0;
    }
};

set <int, comp> s;

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

    cin >> n >> can;
    a.resize(n);
    k.resize(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> k[i];
        ans += a[i];
        s.insert(i);
    }
    while (can > 0 && ans > 0)
    {
        int ii = *(s.begin());
        s.erase(s.begin());
        int go = min(can, (long long)max(1, a[ii] / k[ii]));
        can -= go;
        ans -= go * k[ii];
        a[ii]  = max(0, a[ii] - k[ii] * go);
        s.insert(ii);
    }
    cout << ans;
}
