#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef long long ll;

void solve(int n, int s) {
    vector< pair<int, int> > a(n);
    set< pair<int, int> > q;
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &a[i].fi, &a[i].se);
        a[i].se = min(a[i].fi, a[i].se);
        q.insert({-a[i].se, i});
    }

    while (s > 0 && !q.empty()) {
        auto v = *q.begin();
        q.erase(q.begin());

        int i = v.se;
        int del = 0;
        if (a[i].fi == a[i].se) {
            del = 1;
        } else {
            int can = a[i].fi / a[i].se;
            del = min(can, s);
        }
        s -= del;
        a[i].fi -= del * a[i].se;
        a[i].se = min(a[i].fi, a[i].se);
        if (a[i].fi != 0) {
            q.insert({-a[i].se, i});
        }
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i].fi;
    }

    printf("%lld\n", ans);
}

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

    int n, s;
    while (scanf("%d%d", &n, &s) == 2) {
        solve(n, s);
    }
}
