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


using namespace std;

struct wall {
    int attackers, defender, idx;
    wall(int a, int b, int i) {
        attackers = a;
        defender = b;
        idx = i;
    }
    bool operator <(const wall& other) const {
        int aperd_one = min(attackers, defender);
        int aperd_other = min(other.attackers, other.defender);
        return aperd_one > aperd_other or (aperd_one == aperd_other and idx < other.idx);
    }
};
int main() {
    freopen("castle.in", "r", stdin);
    freopen("castle.out", "w", stdout);
    set<wall > attackers;
    int n, defs, a, b;
    cin >> n >> defs;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        attackers.insert(wall(a, b, i));
    }
    while (defs > 0 and !attackers.empty()) {
        wall c = *attackers.begin();
        if (c.attackers > c.defender) {
            int cur_defs =  min(c.attackers / c.defender, defs);
            c.attackers -= cur_defs * c.defender;
            defs -= cur_defs;
            attackers.erase(attackers.begin());
            attackers.insert(c);
        } else {
            defs--;
            attackers.erase(attackers.begin());
        }
    }
    long long ans = 0;
    for (wall w : attackers) {
        ans += w.attackers;   
    }
    cout << ans << endl;
}
