#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, f;
  cin >> n >> f;
  vector<long long> loss;
  long long sold = 0;
  for (long long i = 0; i < n; ++i) {
    long long k, l;
    cin >> k >> l;
    sold += min(k, l);
    if (k >= l) continue;
    long long tmp = min(k, l - k);
    loss.push_back(tmp);
  }
  sort(loss.begin(), loss.end(), greater<long long>());
  for (long long i = 0; i < f and i < loss.size(); ++i) sold += loss[i];
  cout << sold << "\n";
}
