#include <bits/stdc++.h>
using namespace std;
long long n, f, k[100005], l[100005];
vector<pair<long long, long long> > s;
long long result = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> f;
  s.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> k[i] >> l[i];
    s[i].second = i;
    if (l[i] >= k[i]) s[i].first = min(l[i], k[i] * 2) - k[i];
  }
  sort(s.begin(), s.end());
  reverse(s.begin(), s.end());
  for (int i = 0; i < f; i++) k[s[i].second] *= 2;
  for (int i = 0; i < n; i++) result += min(k[i], l[i]);
  cout << result << "\n";
  return 0;
}
