#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, f;
  priority_queue<int> q;
  while (scanf("%d%d", &n, &f) != EOF) {
    while (!q.empty()) {
      q.pop();
    }
    long long nmax = 0;
    long long k, l;
    for (int i = 0; i < n; ++i) {
      cin >> k >> l;
      if (l <= k) {
        nmax += l;
        continue;
      } else {
        nmax += k;
        if (2 * k >= l)
          q.push(l - k);
        else
          q.push(k);
      }
    }
    for (int i = 0; i < f; ++i) {
      if (q.empty()) break;
      nmax += q.top();
      q.pop();
    }
    cout << nmax << endl;
  }
  return 0;
}
