#include <bits/stdc++.h>
using namespace std;
long long i, n, k, sum;
struct graph {
  long long a, b;
} s[100001];
bool cmp(graph a, graph b) {
  return (min(a.a << 1, a.b) - min(a.a, a.b) >
          min(b.a << 1, b.b) - min(b.a, b.b));
}
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> s[i].a >> s[i].b;
  }
  sort(s + 1, s + n + 1, cmp);
  for (i = 1; i <= n; i++)
    if (i <= k)
      sum += min(s[i].a << 1, s[i].b);
    else
      sum += min(s[i].a, s[i].b);
  cout << sum;
}
