#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define FOR(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define MAXN 100000
#define S second
#define F first
using namespace std;

ll k[MAXN + 1];
ll a[MAXN + 1];
ll m[MAXN + 1];
#define FILENAME "castle"
int main()
{
    freopen(FILENAME".in", "r", stdin);
    freopen(FILENAME".out", "w", stdout);
    ll n, s;
    cin >> n >> s;
    vector<pair<ll, ll> > p(MAXN + 1);
    FOR(i, n)
    {
        cin >> a[i] >> k[i];
        p[i] = {-k[i], a[i]};
    }
    sort(p.begin(), p.end());
    ll ost, ans = 0;
    vector <ll> r;
    ll last = 0;
    FOR(i, n)
        m[i] = p[i].S;
    FOR(i, n){
        p[i].F *= -1;
        if(s == 0){
            last = i - 1;
            break;
        }
        if(s >= p[i].S / p[i].F)
        {
            s -= p[i].S / p[i].F;
            ost = p[i].S % p[i].F;
            m[i] = ost;
            r.pb(-ost);
        }
        else{
            m[i] = p[i].S - p[i].F * s;
            s = 0;
        }
    }
    sort(r.begin(), r.end());
    if(s > 0){
        ll now = 0;
        while(s > 0 && now < r.size())
        {
            r[now] = 0;
            now++;
            s--;
        }
        FOR(i, r.size())
            ans -= r[i];
        cout << ans;
        return 0;

    }
    ll last2 = 0, mns = 0;
    if(m[last] >= p[last].S)
        last--;
    while(last >= 0 && last2 < r.size() && -r[last2] > p[last].F)
    {
        mns += -r[last2];
        m[last] += p[last].F;//mb k[i] + m[i] > a[i]
        if(m[last] >= p[last].S)
            last--;
        last2++;
    }
    FOR(i, n)
        ans += m[i];
    //cout << ans << " " << mns << endl;
    cout << ans - mns;
    return 0;
}
