#include <bits/stdc++.h>
using namespace std;
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  long long n, f, c, p;
  vector<pair<long long, int> > diff;
  cin >> n >> f;
  vector<long long> client, product;
  for (int i = 0; i < n; i++) {
    cin >> p >> c;
    client.push_back(c);
    product.push_back(p);
    if (c > p) {
      long long dif = c - p;
      if (p < dif) dif = p;
      diff.push_back(make_pair(dif, i));
    }
  }
  if (diff.size() > 0) {
    sort(diff.begin(), diff.end());
    int ind = diff.size() - 1;
    for (int i = 0; i < f; i++) {
      if (ind < 0) break;
      int index = diff[ind].second;
      product[index] *= 2;
      ind--;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += min(client[i], product[i]);
  }
  cout << ans;
  return 0;
}
