#include <bits/stdc++.h>

using namespace std;

const int max_n = 200000;

struct node {
    long long a, k;
};

node ar[max_n];
node abc[max_n];

bool cmp(node x, node y) {
    return (x.k < y.k || (x.k == y.k && x.a < y.a));
}

int main()
{
    freopen ("castle.in", "r", stdin);
    freopen ("castle.out", "w", stdout);
    long long n, sum;
    cin >> n >> sum;
    for (int i = 0; i < n; i++) {
        cin >> ar[i].a >> ar[i].k;
    }
    sort(ar, ar + n, cmp);
    for (int i = 0; i < sum; i++) {
        int cur = -1;
        long long cu = -1;
        bool b = false;
        for (int j = 0; j < n; j++) {
            if (ar[j].a >= ar[j].k) {
                if (cu == -1 || ar[j].k > cu) {
                    cu = ar[j].k;
                    cur = j;
                    b = true;
                }
            } else {
                if (cu == -1 || ar[j].a > cu) {
                    cu = ar[j].a;
                    cur = j;
                    b = false;
                }
            }
        }
        if (cu < 1) {
            break;
        }
        if (b) {
            ar[cur].a -= ar[cur].k;
        } else {
            ar[cur].a = 0;
        }
    }
    long long s = 0;
    for (int i = 0; i < n; i++) {
        s += ar[i].a;
    }
    cout << s << endl;
    return 0;
}
