#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 6, M = 3e5 + 5, mod = 1e9 + 7;
const double EPS = 1e-3;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int n, f, numP, numC, preB;
long long totB;
int main() {
  vector<int> postB;
  scanf("%d %d", &n, &f);
  for (int i = 0; i < int(n); i++) {
    scanf("%d %d", &numP, &numC);
    totB += min(numP, numC);
    preB = min(numP, numC);
    postB.push_back(min(2 * numP, numC) - preB);
  }
  sort(((postB).begin()), ((postB).end()));
  int sz = postB.size();
  for (int i = sz - 1; f > 0; --i) totB += postB[i], f--;
  printf("%lld\n", totB);
  return 0;
}
