#include <bits/stdc++.h>
#define pii pair<long long, long long>
#define F first
#define S second

using namespace std;

long long a[100001];
long long k[100001];

int main()
{
    #ifndef DEBUG
    freopen("castle.in", "r", stdin);
    freopen("castle.out", "w", stdout);
    #else
    freopen("input.txt", "r", stdin);
    #endif // DEBUG
    int n;
    long long s;
    cin >> n >> s;
    multiset<pii> st;
    long long sum = 0;
    for (int i = 0; i < n; i++){
        cin >> a[i] >> k[i];
        sum += a[i];
        if (k[i] < a[i])
            st.insert(pii(-k[i], a[i]));
        else
            st.insert(pii(-a[i], a[i]));
    }
    while (!st.empty() && s > 0){
        auto it = st.begin();
        pii p = *it;
        st.erase(it);
        if (p.F + p.S == 0){
            s--;
            sum -= p.S;
        }
        else{
            p.F = -p.F;
            long long k = (p.S / p.F);
            if (s <= k){
                sum -= s * p.F;
                break;
            }
            s -= k;
            sum -= k * p.F;
            p.F = -(p.S % p.F);
            p.S = -p.F;
            if (p.S != 0){
                st.insert(p);
            }
        }
    }
    cout << sum;
    return 0;
}
