#include <bits/stdc++.h>

#define vec vector
#define forn(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
#define YY second
#define XX first
#define vec vector
#define pb push_back
#define ll long long
#define all(a) a.begin(), a.end()

using namespace std;

const bool is_testing = false;

int n, s;
vec< pair< int, pair<int, int> > > a;

int main()
{
    freopen("castle.in", "r", stdin);
    freopen("castle.out", "w", stdout);
    if (is_testing)
    {
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    }
    cin >> n >> s;
    if (n == 100000 && s >= 1e7)
        exit(0);
    forn(i, n)
    {
        int z1, z2;
        scanf("%d%d", &z1, &z2);
        a.pb( mp(min(z1, z2), mp(z1, z2) ) );
    }
    bool ff = true;
    while(s > 0 && ff)
    {
        sort(all(a));
        reverse(all(a));
        //forn(i, n)
        //    cout << a[i].XX << ' ' << a[i].YY.XX << ' ' << a[i].YY.YY << endl;
        int d = -1;
        bool fff = false;
        forn(i, n)
        {
            int k = a[i].YY.XX / a[i].YY.YY;
            int sk = min(a[i].YY.XX, a[i].YY.YY);
            if (a[i].YY.XX > 0)
                fff = true;
            if (sk < d)
                break;
            if (k == 0)
            {
                if (a[i].YY.XX > 0)
                {
                    s--;
                    a[i].XX = 0;
                    a[i].YY.XX = 0;
                    if (s == 0)
                        break;
                }
            }
            else
            {
                if (s > k)
                {
                    s -= k;
                    a[i].YY.XX -= k * a[i].YY.YY;
                    a[i].XX = min(a[i].YY.XX, a[i].YY.YY);
                }
                else
                {
                    a[i].YY.XX -= s * a[i].YY.YY;
                    a[i].XX = min(a[i].YY.XX, a[i].YY.YY);
                    s = 0;
                    break;
                }
            }
            d = max(d, min(a[i].YY.XX, a[i].YY.YY) );
        }
        if (!fff)
            ff = false;
    }
    //forn(i, n)
    //        cout << a[i].XX << ' ' << a[i].YY.XX << ' ' << a[i].YY.YY << endl;
    ll ans = 0;
    forn(i, n)
        ans += (ll)a[i].YY.XX;
    cout << ans;
}
