#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e6;
const long long int MOD = 1e9 + 7;
const int MAX = 505;
using namespace std;
void solve() {
  int n, f;
  cin >> n >> f;
  vector<long long> v;
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    long long k, l;
    cin >> k >> l;
    long long temp = min(k, l);
    res += temp;
    k *= 2;
    v.push_back(min(k, l) - temp);
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < f; ++i) {
    res += v[i];
  }
  cout << res << endl;
}
int main() {
  solve();
  return 0;
}
