#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::string;
using std::array;
using std::pair;
using std::make_pair;

using std::min;
using std::max;
using std::abs;

template <typename T>
T input() {
    T res;
    cin >> res;
    return res;
}

#ifdef LOCAL
#define LASSERT(x) assert(x)
#else
#define LASSERT(x) {}
#endif

struct node {
    uint32_t a;
    uint32_t k;

    bool operator<(const node other) const {
        return min(a, k) > min(other.a, other.k);
    }
};

int main() {
    // save with C-x C-s
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef LOCAL
#define TASK "castle"
    freopen(TASK ".in", "r", stdin);
    freopen(TASK ".out", "w", stdout);
#endif

    std::multiset<node> all;
    uint32_t n, s;
    cin >> n >> s;

    for (uint32_t i = 0; i != n; ++i) {
        uint32_t a, k;
        cin >> a >> k;

        all.insert(node {a, k});
    }

    for (uint32_t i = 0; i != s and not all.empty(); ++i) {
        node top = *all.begin();
        all.erase(all.begin());

        top.a -= min(top.a, top.k);
        if (top.a != 0)
            all.insert(top);
    }

    uint32_t sum = 0;
    for (auto v: all)
        sum += v.a;
    cout << sum << "\n";
    return 0;
}