#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <cstring>

using namespace std;

typedef long long ll;

const int N = 2e5;

int a[N], k[N];
set <pair <int, int> > ar;

int main()
{
    int n, s;
    ios_base::sync_with_stdio(0);
    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];
        int val = min(k[i], a[i]);
        if (val > 0)
            ar.insert(make_pair(val, i));
    }
    while (s > 0 && ar.size() > 0)
    {
        pair <int, int> k1 = *ar.rbegin();
        ar.erase(k1);
        int i = k1.second;
        int f = a[i], q = k[i];
        int ct = a[i] / k[i];
        if (ct == 0)
        {
            s -= 1;
            a[i] = 0;
            if (s < 0)
                a[i] += (-s) * k[i];
            int val = min(k[i], a[i]);
            if (val > 0)
                ar.insert(make_pair(val, i));
            continue;
        }
        s -= ct;
        a[i] %= k[i];
        if (s < 0)
            a[i] += (-s) * k[i];
        int val = min(k[i], a[i]);
        if (val > 0)
            ar.insert(make_pair(val, i));
    }
    ll ans = 0;
    for (int i = 0; i< n; i++)
        ans += a[i];
    cout << ans << endl;
    return 0;
}
