#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 228;
int64_t k[MAXN], l[MAXN];
int64_t d[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n, f;
  int64_t ans = 0;
  cin >> n >> f;
  for (int i = 0; i < n; ++i) {
    cin >> k[i] >> l[i];
    ans += min(k[i], l[i]);
    if (2 * k[i] > l[i]) {
      d[i] = l[i] - min(l[i], k[i]);
    } else {
      d[i] = k[i];
    }
  }
  sort(d, d + n);
  reverse(d, d + n);
  for (int i = 0; i < f; ++i) {
    ans += d[i];
  }
  cout << ans << endl;
  return 0;
}
