#include <bits/stdc++.h>
using namespace std;
long long n, f, x, y;
long long arr1[100000 + 10];
pair<long long, long long> arr2[100000 + 10];
bool id[100000 + 10];
long long ans = 0;
bool cmp(pair<long long, long long> &a, pair<long long, long long> &b) {
  return ((min(2 * a.first, a.second) - min(a.first, a.second)) >
          (min(2 * b.first, b.second) - min(b.first, b.second)));
}
int main() {
  cin >> n >> f;
  for (int i = 0; i < n; i++) {
    cin >> arr2[i].first;
    cin >> arr2[i].second;
  }
  sort(arr2, arr2 + n, cmp);
  for (int i = 0; i < n; ++i) {
    if (f) {
      ans += min(2 * arr2[i].first, arr2[i].second);
      f--;
    } else
      ans += min(arr2[i].first, arr2[i].second);
  }
  cout << ans;
  return 0;
}
