#include <bits/stdc++.h>

using namespace std;

struct segment {
    int a, k;
};
bool comp(segment a, segment b) {
    return a.k < b.k;
}

int main() {
    freopen("castle.in", "rt", stdin);
    freopen("castle.out", "wt", stdout);
    const int MAX_N = 100000;
    int n, s, st;
    segment segs[2 * MAX_N];
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &segs[2 * i].a, &segs[2 * i].k);
        segs[2 * i + 1].a = segs[2 * i].a % segs[2 * i].k;
        segs[2 * i + 1].k = segs[2 * i + 1].a;
        segs[2 * i].a -= segs[2 * i + 1].a;
    }
    sort(segs, segs + 2 * n, comp);
//    for (int i = 0; i < 2 * n; i++) {
//        printf("%d %d\n", segs[i].a, segs[i].k);
//    }
    for (int i = 2 * n - 1; i >= 0; i--) {
        if (segs[i].k == 0) {
            break;
        }
        st = min(segs[i].a / segs[i].k, s);
        s -= st;
        segs[i].a -= st * segs[i].k;
        segs[i].a = max(segs[i].a, 0);
    }
    long long ans = 0;
    for (int i = 0; i < 2 * n; i++) {
        ans += segs[i].a;
    }
    cout << ans << endl;
}
