#include <bits/stdc++.h>
using namespace std;
inline int nxt() {
  int wow;
  scanf("%d", &wow);
  return wow;
}
inline long long int lxt() {
  long long int wow;
  scanf("%lld", &wow);
  return wow;
}
struct data {
  long long int x, y;
} a[100002];
bool comp(data one, data two) {
  long long int ekka, dokka;
  long long int fp = min(one.x, one.y);
  long long int sp = 0;
  if (one.y > one.x) sp = min(one.x, one.y - fp);
  ekka = sp;
  fp = min(two.x, two.y);
  sp = 0;
  if (two.y > two.x) sp = min(two.x, two.y - fp);
  dokka = sp;
  if (ekka > dokka) return true;
  return false;
}
int main() {
  int n = nxt(), f = nxt();
  for (int i = 0; i < n; i++) {
    a[i].x = lxt(), a[i].y = lxt();
  }
  sort(a, a + n, comp);
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    if (i < f) a[i].x *= 2;
    sum += min(a[i].x, a[i].y);
  }
  cout << sum << endl;
  return 0;
}
