#include <bits/stdc++.h>

using namespace std;

ifstream inp("castle.in");
ofstream outp("castle.out");

bool srt(pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
}

int main() {
    int n, s;
    inp >> n >> s;
    pair<int, int> ak[100000];
    int attackers = 0;
    int defenders = s;
    for(int i = 0; i < n; i++) {
        int a, k;
        inp >> a >> k;
        if(k > a) k = a;
        ak[i] = {a, k};
        attackers += a;
    }
    int last_defs = 0;
    int delta_n = 0;
    while(defenders != last_defs && defenders > 0) {
            cout << endl;
        cout << last_defs << ' ' << defenders << endl;
        last_defs = defenders;
        sort(ak, ak + n, srt);
        n -= delta_n;
        delta_n = 0;
        cout << "kek" << endl;
        for(int i = 0; i < n; i++) {
            cout << ak[i].first << ' ' << ak[i].second << endl;
        }
        cout << "kek" << endl;
        for(int i = 0; i < n; i++) {
            int pos_defs = min(ak[i].first / ak[i].second, defenders);
            int remain = ak[i].first - ak[i].second * pos_defs;
            if(remain == 0) delta_n++;
            cout << pos_defs << 'l' << remain << endl;
            attackers -= (ak[i].first - remain);
            ak[i].first = remain;
            ak[i].second = min(remain, ak[i].second);
            defenders -= pos_defs;
            if(i < n - 1 && ak[i].second >= ak[i + 1].second) {
                i--;
            }
        }
    }
    cout << attackers;
    return 0;
}
