#include <bits/stdc++.h>

using namespace std;


#define int long long
#define mp make_pair





struct block
{
    int cost;
    int cnt;
    int now;
    int num;
    block(){}
    block(int a, int b, int c, int d)
    {
        cnt = a;
        cost = b;
        now = c;
        num = d;
    }
};
block a[100001];

bool operator <(block a, block b)
{
    return(a.now > b.now) || (a.now == b.now && a.cnt > b.cnt) || (a.now == b.now && a.cnt == b.cnt && a.cost < b.cost) || (a.now == b.now && a.cnt == b.cnt && a.cost == b.cost && a.num < b.num);
}


signed main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

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


    ios_base::sync_with_stdio(0);
    int sum = 0;
    int n, s;
    cin >> n >> s;
    multiset <block> c;
    for (int i = 0; i < n; ++i)
    {
        int p, q;
        cin >> p >> q;
        int t = min(p, q);
        a[i] = block(p, q, t, i);
        c.insert(a[i]);
        sum += p;
    }
    while (sum > 0 && s > 0)
    {
        block t = *(c.begin());
        c.erase(t);
        if (t.cnt >= t.cost)
        {
            int k = t.cnt / t.cost;
            if (s >= k)
            {
                s -= k;
                t.cnt -= k * t.cost;
                sum -= k * t.cost;
                t.now = t.cnt;
            }
            else
            {
                sum -= s * t.cost;
                t.cnt -= s * t.cost;
                s = 0;
            }
        }
        else
        {
            s--;
            sum -= t.cnt;
            t.cnt = 0;
            t.now = 0;
        }
        c.insert(t);
//        for (auto i : c)
//            cout << i.cnt << ' ' << i.cost << ' ' << i.now << '\n';
//        for (auto i : c)
//            cout << i.cnt << ' ' << i.cost << ' ' << i.now << '\n';
    }
    cout << sum;



}
