#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 11;
long long ans;
int n, f;
pair<int, int> arr[MAXN];
inline bool myComp(pair<int, int> &a, pair<int, int> &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 >> arr[i].first >> arr[i].second;
  sort(arr, arr + n, myComp);
  for (int i = 0; i < n; ++i)
    if (i < f)
      ans += min(2 * arr[i].first, arr[i].second);
    else
      ans += min(arr[i].first, arr[i].second);
  cout << ans << endl;
  return 0;
}
