#include <bits/stdc++.h>
using namespace std;
bool isprime(int n) {
  if (n == 1) return false;
  if (n == 2 || n == 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i += 6) {
    if ((n % i == 0) || (n % (i + 2) == 0)) return false;
  }
  return true;
}
long long binpow(long long a, long long b) {
  if (b == 0) return 1;
  long long res = binpow(a, b / 2);
  if (b % 2)
    return res * res * a;
  else
    return res * res;
}
long long ncr(long long x, long long y) {
  long long ans = 1;
  for (long long i = 1; i <= y; ++i) {
    ans *= (x - y + i);
    ans /= i;
  }
  return ans;
}
long long phi(long long n) {
  long long result = n;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      result -= result / i;
    }
  }
  if (n > 1) result -= result / n;
  return result;
}
bool comp(pair<long long, long long> x, pair<long long, long long> y) {
  return x.second > y.second;
}
bool comp1(pair<long long, long long> x, pair<long long, long long> y) {
  return x.first > y.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, f;
  cin >> n >> f;
  long long tt = 0;
  vector<long long> ops(n);
  for (long long i = 0; i < n; i++) {
    long long k, l;
    cin >> k >> l;
    tt += min(k, l);
    ops[i] = min(2 * k, l) - min(k, l);
  }
  sort(ops.begin(), ops.end(), greater<int>());
  for (int i = 0; i < f; i++) tt += ops[i];
  cout << tt << endl;
  return 0;
}
