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