#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, f;
  cin >> n >> f;
  long long int a[n];
  long long int k, l;
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> k >> l;
    sum += min(k, l);
    if (k > l)
      a[i] = 0;
    else
      a[i] = min(k * 2, l) - min(k, l);
  }
  sort(a, a + n, greater<long long int>());
  long long int j = 0;
  while (f && j < n) {
    if (a[j] > 0) {
      sum += a[j];
      f--;
    }
    j++;
  }
  cout << sum;
}
