#include<bits/stdc++.h>

using namespace std;

int main()
{
    freopen("castle.in", "r", stdin);
    freopen("castle.out", "w", stdout);
    long long n, s;
    cin >> n >> s;
    vector<pair<long long, long long>> a(n);
    for (long long i = 0; i < n; i++)
    {
        cin >> a[i].second >> a[i].first;
    }
    sort(a.rbegin(), a.rend());
    for (long long i = 0; i < n; i++)
    {
        swap(a[i].first, a[i].second);
    }
    vector<long long> ans(n);
    set<pair<long long, long long>> osts;
    long long prefsum = 0;
    for (long long i = 0; i < n; i++)
    {
        if (s - prefsum != 0)
        {
            ans[i] += min(s - prefsum, (a[i].first + a[i].second - 1) / a[i].second);
        }
        if (a[i].second * ans[i] > a[i].first)
        {
            osts.insert(make_pair(a[i].second - a[i].second * ans[i] + a[i].first, i));
            prefsum += ans[i];
            continue;
        }
        while (a[i].second * ans[i] < a[i].first)
        {
            long long need;
            if (a[i].first - a[i].second * ans[i] < a[i].second)
            {
                need = a[i].first - a[i].second * ans[i];
            }
            else
            {
                need = a[i].second;
            }
            auto it = osts.begin();
            if (it == osts.end())
            {
                break;
            }
            pair<long long, long long> tt = *it;
            if (tt.first < a[i].first - a[i].second * ans[i])
            {
                ans[i]++;
                ans[tt.second]--;
                prefsum--;
                osts.erase(it);
            }
            else
            {
                break;
            }
        }
        prefsum += ans[i];
        //cout << prefsum << endl;
    }
    long long ansans = 0;
    for (long long i = 0; i < n; i++)
    {
        //cout << ans[i] << " ";
        ansans += max(0, a[i].first - ans[i] * a[i].second);
    }
    cout << ansans;
}
