#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, f;
  cin >> n >> f;
  int k[n], l[n];
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    cin >> k[i] >> l[i];
    v.push_back(make_pair(min(2 * k[i], l[i]) - min(k[i], l[i]), i));
  }
  sort(v.rbegin(), v.rend());
  long long sum = 0;
  int pos;
  for (int i = 0; i < f; i++) {
    pos = v[i].second;
    sum = sum + min(2 * k[pos], l[pos]);
  }
  for (int i = f; i < n; i++) {
    pos = v[i].second;
    sum = sum + min(k[pos], l[pos]);
  }
  cout << sum << endl;
  return 0;
}
