#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, f;
  cin >> n >> f;
  long long products[n], clients[n];
  long long additional[n];
  long long sold = 0;
  for (long long i = 0; i < n; i++) {
    cin >> products[i] >> clients[i];
    if (clients[i] <= products[i])
      additional[i] = 0;
    else {
      if (clients[i] >= 2 * products[i]) {
        additional[i] = products[i];
      } else {
        additional[i] = clients[i] - products[i];
      }
    }
    sold += min(products[i], clients[i]);
  }
  sort(additional, additional + n, greater<int>());
  for (long long i = 0; i < f; i++) {
    sold += additional[i];
  }
  cout << sold;
  return 0;
}
