#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
ll n, s;
ll a[100000];
ll k[100000];
ll b[100000];
int d[100000];
set <pair <ll, int> > t;
bool comp(int x, int y) {
    if (k[x] > k[y]) return true;
    return false;
}
bool comp1(int x, int y) {
    if (min(k[y], a[y] - b[y] * k[y]) < min(k[x], a[x] - b[x] * k[x]) ) return true;
    return false;
}
int main() {
    freopen("castle.in", "r", stdin);
    freopen("castle.out", "w", stdout);
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> k[i];
        b[i] = 0;
        d[i] = i;
    }
    sort(d, d + n, comp);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (s == 0) break;
        while (t.size() > 0) {
            int j = (*(t.begin())).second;
            int l = a[j] - b[j] * k[j];
            if (l > k[d[i]] && s > 0) {
                b[j]++;
                s--;
                t.erase(mp(-l, j));
            }
            else break;
        }
        b[d[i]] += min(s, a[d[i]] / k[d[i]]);
        s -= min(s, a[d[i]] / k[d[i]]);
        t.insert(mp(-(a[d[i]] - b[d[i]] * k[d[i]]), d[i]));
    }
    sort(d, d + n, comp1);
    for (int i = 0; i < n; i++) {
        if (s > 0) {
            b[d[i]]++;
            s--;
        }
    }
    for (int i = 0; i < n; i++) ans += max(0LL, a[i] - b[i] * k[i]);
    cout << ans << "\n";
}
