#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second > b.second);
}
int main() {
  vector<int> vec;
  int n, f;
  long long sum = 0;
  cin >> n >> f;
  int j = 0;
  for (int i = 0; i < n; ++i) {
    int k, l;
    cin >> k >> l;
    sum += min(k, l);
    vec.push_back(min(2 * k, l) - min(k, l));
  }
  sort(vec.begin(), vec.end(), greater<int>());
  for (int i = 0; i < f; ++i) sum += vec[i];
  cout << sum << endl;
}
