#include <bits/stdc++.h>
using namespace std;
bool customSort(const pair<unsigned long long, unsigned long long> &a,
                const pair<unsigned long long, unsigned long long> &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(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  unsigned long long N, F;
  cin >> N >> F;
  vector<pair<unsigned long long, unsigned long long>> ARR(N);
  unsigned long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> ARR[i].first >> ARR[i].second;
    sum += min(ARR[i].first, ARR[i].second);
  }
  sort(ARR.begin(), ARR.end(), customSort);
  unsigned long long j = 0;
  while (F--) {
    sum -= min(ARR[j].first, ARR[j].second);
    sum += min(2 * ARR[j].first, ARR[j].second);
    j += 1;
  }
  cout << sum;
  return 0;
}
