#include <bits/stdc++.h>
using namespace std;
vector<long long> surplus;
int n, f;
int main() {
  ios_base::sync_with_stdio(false);
  long long ans(0ll);
  cin >> n >> f;
  for (int i = 0; i < n; i++) {
    int prod, cust;
    cin >> prod >> cust;
    ans += min(prod, cust);
    surplus.push_back(min(2 * prod, cust) - min(prod, cust));
  }
  sort(surplus.rbegin(), surplus.rend());
  for (int i = 0; i <= surplus.size() && f--; i++) {
    ans += surplus[i];
  }
  cout << ans;
  return 0;
}
