#include <bits/stdc++.h>

using namespace std;

int main()
{
    freopen("castle.in", "r", stdin);
    freopen("castle.out", "w", stdout);
    int n;
    long long summa;
    cin >> n >> summa;
    multiset<pair<long long, long long> > s;
    long long answer = 0;
    for (int i = 0; i < n; i++){
        pair<long long, long long> a;
        cin >> a.second >> a.first;
        answer += a.second;
        a.first *= -1;
        s.insert(a);
    }
    while (summa > 0 && answer > 0){
        pair<long long, long long> a = *(s.begin());
        s.erase(s.begin());
        a.first *= -1;
        if (a.first == 0)
            break;
        summa -= a.second / a.first;
        answer -= a.second - a.second % a.first;
        a.second %= a.first;
        a.first = a.second;
        s.insert(a);
    }
    cout << answer;
    return 0;
}
