#include <bits/stdc++.h>
using namespace std;


struct Treap
{
    int key, val, prior, tsize;
    Treap *left, *right;

    Treap(int _key = 0, int _val = 0)
    {
        key = _key;
        val = _val;
        tsize = 1;
        prior = (rand() << 15) ^ rand();
        left = right = nullptr;
    }
};


int getsize(Treap *t)
{
    return (t) ? t->tsize : 0;
}


void refresh(Treap *t)
{
    if (t)
    {
        t->tsize = getsize(t->left) + 1 + getsize(t->right);
    }
    return;
}


Treap *t_merge(Treap *t1, Treap *t2)
{
    if (!t1)
    {
        return t2;
    }
    if (!t2)
    {
        return t1;
    }
    if (t1->prior <= t2->prior)
    {
        t1->right = t_merge(t1->right, t2);
        refresh(t1);
        return t1;
    }
    else
    {
        t2->left = t_merge(t1, t2->left);
        refresh(t2);
        return t2;
    }
}


typedef pair<Treap*, Treap*> tt;


tt t_split(Treap *t, int k)
{
    if (!t)
    {
        return {nullptr, nullptr};
    }
    if (t->key >= k)
    {
        tt parts = t_split(t->left, k);
        t->left = parts.second;
        parts.second = t;
        refresh(parts.first);
        refresh(parts.second);
        return parts;
    }
    else
    {
        tt parts = t_split(t->right, k);
        t->right = parts.first;
        parts.first = t;
        refresh(parts.first);
        refresh(parts.second);
        return parts;
    }
}


pair<int, int> getkth(Treap *t, int k)
{
    if (!t)
    {
        return {0, 0};
    }
    if (k == getsize(t->left) + 1)
    {
        return {t->key, t->val};
    }
    return (getsize(t->left) + 1 >= k) ? getkth(t->left, k) : getkth(t->right, k - getsize(t->left) - 1);
}


void add(Treap *&t, int key, int val)
{
    Treap *nt = new Treap(key, val);
    tt parts = t_split(t, key);
    t = t_merge(t_merge(parts.first, nt), parts.second);
    return;
}


void out(Treap *t)
{
    if (t)
    {
        out(t->left);
        cout << " " << t->key << " " << t->val << endl;
        out(t->right);
    }
    return;
}


int main()
{
    freopen("castle.in", "r", stdin);
    freopen("castle.out", "w", stdout);
    long long n, s;
    cin >> n >> s;
    long long ans = 0;
    Treap *t = nullptr;
    vector< pair<long long, long long> > wall(n);
    for (long long i = 0; i < n; ++i)
    {
        cin >> wall[i].second >> wall[i].first;
        ans += wall[i].second;
        add(t, wall[i].first, wall[i].second);
    }
    for (; (s > 0) && (ans > 0);)
    {
        pair<int, int> keycnt = getkth(t, getsize(t));
        s -= keycnt.second / keycnt.first;
        long long f = (keycnt.second / keycnt.first) * keycnt.first;
        ans -= f;
        tt parts = t_split(t, keycnt.first);
        t = parts.first;
        add(t, keycnt.second - f, keycnt.second - f);
    }/*
    sort(wall.begin(), wall.end());
    reverse(wall.begin(), wall.end());
    vector<int> p;
    int u = 0;
    //cout << "first part" << endl;
    for (long long i = 0; i < n; ++i)
    {
        //cout << "s = " << s << ", ans = " << ans << ", attack[i] = " << wall[i].second << ", one can defend from " << wall[i].first << endl;
        if (s > 0)
        {
            multiset<long long>::iterator it = p.begin();
            for (; (u < p.size()) && (p[u] >= wall[i].first); ++u)
            {
                --s;
                ans -= p[u];
            }
            if (wall[i].second / wall[i].first <= s)
            {
                s -= wall[i].second / wall[i].first;
                long long t = (wall[i].second / wall[i].first) * wall[i].first;
                ans -= t;
                wall[i].second -= t;
                p.push_back(-wall[i].second);
                wall[i].second = 0;
            }
            else
            {
                long long t = wall[i].first * s;
                ans -= t;
                wall[i].second -= t;
                s = 0;
            }
            swap(wall[i].first, wall[i].second);
        }
    }
    sort(wall.begin(), wall.end());
    reverse(wall.begin(), wall.end());
    /*cout << "second part" << endl;
    for (long long i = 0; i < n; ++i)
    {
        cout << "s = " << s << ", ans = " << ans << ", attack[i] = " << wall[i].first << ", one can defend from " << wall[i].second << endl;
        if (s > 0)
        {
            if (wall[i].first > 0)
            {
                --s;
                ans -= wall[i].first;
            }
        }
    }*/
    cout << ans << endl;
    return 0;
}
