#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int>> vec;
vector<long long int> diff;
int main() {
  long long int n, f, temp, a, b, su = 0;
  ;
  cin >> n >> f;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    vec.push_back({a, b});
    su = su + min(a, b);
  }
  for (int i = 0; i < n; i++) {
    int x = min(vec[i].first, vec[i].second);
    int y = min(vec[i].first * 2, vec[i].second);
    diff.push_back(y - x);
  }
  sort(diff.begin(), diff.end());
  int p = diff.size() - 1;
  while (f--) {
    su = su + diff[p];
    p--;
  }
  cout << su << endl;
}
