#include <bits/stdc++.h>
using namespace std;
int n, f;
struct mang {
  int k, l, dou, id;
} a[1000005];
void setup() {
  cin >> n >> f;
  for (int i = (1); i <= (n); i++) {
    cin >> a[i].k >> a[i].l;
    a[i].id = i;
    a[i].dou = min(a[i].k * 2, a[i].l) - a[i].k;
  }
}
void init() {}
bool cmp(mang p, mang q) { return p.dou > q.dou; }
void work() {
  sort(a + 1, a + n + 1, cmp);
  long long s = 0;
  for (int i = (1); i <= (f); i++) s += a[i].dou + a[i].k;
  for (int i = (f + 1); i <= (n); i++) s += min(a[i].k, a[i].l);
  cout << s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  setup();
  work();
  return 0;
}
