#include <bits/stdc++.h>
using namespace std;
int A[105];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  long long res = 0;
  vector<int> v;
  for (int i = 0; i < n; ++i) {
    int p, l;
    scanf("%d %d", &p, &l);
    int x = min(p, l);
    res += x;
    v.push_back(min(2 * p, l) - x);
  }
  sort(v.begin(), v.end(), greater<int>());
  for (int i = 0; i < k; ++i) {
    res += v[i];
  }
  printf("%I64d\n", res);
}
