#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    a[i] = min(p[i].first * 2, p[i].second) - min(p[i].first, p[i].second);
  }
  sort(a.begin(), a.end(), greater<int>());
  long long int answ = 0;
  for (int i = 0; i < n; ++i) {
    answ += min(p[i].first, p[i].second);
  }
  for (int i = 0; i < k; ++i) {
    answ += a[i];
  }
  cout << answ;
  return 0;
}
