#include <bits/stdc++.h>
using namespace std;
long long x, y, p[100005];
int main() {
  long long n, f;
  scanf("%lld %lld", &n, &f);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%lld %lld", &x, &y);
    sum += min(x, y);
    if (x < y) p[i] = (min(x, y - x));
  }
  sort(p, p + n);
  for (int i = n - 1; f > 0; --i, --f) sum += p[i];
  printf("%lld\n", sum);
  return 0;
}
