#include <bits/stdc++.h>
using namespace std;
struct day {
  int a, b, c;
} d[101000];
int n, k;
bool cmp(day x, day y) { return x.c > y.c; }
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &d[i].a, &d[i].b);
    d[i].c = min(d[i].a * 2, d[i].b) - d[i].a;
  }
  sort(d, d + n, cmp);
  for (int i = 0; i < k; i++) d[i].a *= 2;
  long long ans = 0;
  for (int i = 0; i < n; i++) ans += (long long)min(d[i].a, d[i].b);
  printf("%lld\n", ans);
  return 0;
}
