#include <bits/stdc++.h>
using namespace std;
struct st {
  long long k, l;
  long long zhang;
} kk[100005];
int cmp(st a, st b) { return a.zhang > b.zhang; }
int main() {
  int n, f;
  while (~scanf("%d%d", &n, &f)) {
    long long x, y;
    int i;
    for (i = 0; i < n; i++) {
      scanf("%lld%lld", &x, &y);
      kk[i].k = x;
      kk[i].l = y;
      if (x < y) {
        if (x * 2 < y) {
          kk[i].zhang = x;
        } else
          kk[i].zhang = y - x;
      } else
        kk[i].zhang = 0;
    }
    sort(kk, kk + n, cmp);
    long long ans = 0;
    for (i = 0; i < n; i++) {
      if (f) {
        f--;
        kk[i].k *= 2;
      }
      if (kk[i].k < kk[i].l)
        ans += kk[i].k;
      else
        ans += kk[i].l;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
