#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

using namespace std;

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

    vector < pair <int, pair <int, int> > > arr;
    int n, s;
    cin >> n >> s;
    int tmp1, tmp2, i, effect;

    long long cnt = 0;
    for(i = 0; i < n; i++)
    {
        cin >> tmp1 >> tmp2;
        effect = min(tmp1, tmp2);
        arr.push_back({effect, {tmp1, tmp2}});
        cnt += tmp1;
    }

    while(cnt > 0 and s > 0 and !arr.empty())
    {
        //cout << arr.size() << endl;
        sort(arr.begin(), arr.end());
        pair <int, pair <int, int> > now = arr.back();
        arr.pop_back();

        pair <int, pair <int, int> > new_now = now;
        if(now.second.first < now.second.second)
        {
            cnt -= now.second.first;
            s--;
        }
        else
        {
            int def = min(s, (now.second.first / now.second.second));
            int mod = def * now.second.second;
            //cout << def << " " << mod << endl;
            new_now.second.first -= mod;
            cnt -= mod;
            s -= def;
            new_now.first = min(new_now.second.first, new_now.second.second);
            arr.push_back(new_now);
        }
    }

    cout << max(cnt, (long long)0);
    return 0;

}
