#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, f, i;
  long long int ans = 0;
  vector<int> v;
  cin >> n >> f;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    if (a >= b)
      ans += b;
    else {
      ans += a;
      v.push_back(min(a, b - a));
    }
  }
  int m = v.size();
  sort(v.begin(), v.end());
  for (i = m - 1; i >= 0; i--) {
    if (f == 0) break;
    ans += v[i];
    f--;
  }
  cout << ans << endl;
}
