#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, f;
  cin >> n >> f;
  vector<int> aa(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int k, l;
    cin >> k >> l;
    int a1 = min(k, l);
    int a2 = min(k + k, l);
    sum += a1;
    aa[i] = a2 - a1;
  }
  sort(aa.begin(), aa.end());
  for (int i = n - f; i < n; i++) sum += aa[i];
  cout << sum << endl;
  return 0;
}
