#include <bits/stdc++.h>
using namespace std;
long long mmin(long long a, long long b) { return a < b ? a : b; }
int main() {
  int n, f;
  cin >> n >> f;
  long long k[n];
  long long l[n];
  long long dif[n];
  vector<pair<long long, int> > s;
  for (long long i = 0; i < (long long)n; i++) {
    cin >> k[i] >> l[i];
    dif[i] = l[i] - k[i];
    s.push_back({(mmin(2 * k[i], l[i]) - mmin(k[i], l[i])), i});
  }
  sort(s.begin(), s.end());
  reverse(s.begin(), s.end());
  long long sum = 0;
  int idx = 0;
  for (auto v : s) {
    if (idx < f) {
      int i = v.second;
      sum += min(2 * k[i], l[i]);
    } else {
      int i = v.second;
      sum += min(k[i], l[i]);
    }
    idx++;
  }
  cout << sum;
  return 0;
}
