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

using namespace std;

typedef long long ll;
#define INF 1791791791791791791ll

vector<ll> k;

struct cmp
{
    cmp() {}
    bool operator()(const int& a, const int& b) const
    {
        if (k[a] != k[b])
            return k[a] > k[b];
        return a > b;
    }
};

int main()
{
#ifndef LOCAL
    freopen("castle.in", "r", stdin);
    freopen("castle.out", "w", stdout);
#endif
    int n; ll s;
    cin >> n >> s;
    vector<ll> a(n);
    k.resize(n);
    for (int i = 0; i < n; i++)
        cin >> a[i] >> k[i];
 
    set<int, cmp> st;
    for (int i = 0; i < n; i++)
        st.insert(i);
    while (s > 0 && st.size())
    {
        auto it = st.begin();
        int i = *it;
        st.erase(it);
        
        if (a[i] / k[i] <= s)
        {
            s -= a[i] / k[i];
            a[i] %= k[i];
            k[i] = min(k[i], a[i]);
        }
        else
        {
            a[i] -= s * k[i];
            s = 0;
        }
        if (a[i] > 0)
            st.insert(i);
    }
  
    ll ans = 0;
    for (int i = 0; i < n; i++)
        ans += a[i];
    cout << ans << endl;

    return 0;
}
