#include <bits/stdc++.h>
using namespace std;
long long n, f, i, j, ans;
int a[100001], b[100001], c[100001];
int main() {
  cin >> n >> f;
  for (i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    ans += min(a[i], b[i]);
  }
  if (f == 0) {
    cout << ans << endl;
    return 0;
  }
  for (i = 1; i <= n; i++) {
    c[i] = min(a[i] * 2, b[i]) - min(a[i], b[i]);
  }
  sort(c + 1, c + n + 1);
  for (i = n; i > n - f; i--) {
    ans += c[i];
  }
  cout << ans << endl;
  return 0;
}
