#include <bits/stdc++.h>
using namespace std;
bool pred(const pair<int, int>& a, const pair<int, int>& b) {
  int x1 = min(a.first * 2, a.second) - a.first;
  int x2 = min(b.first * 2, b.second) - b.first;
  return x1 > x2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, c;
  cin >> n >> c;
  unsigned long long int sum = 0;
  vector<pair<int, int>> S;
  for (int i = 0; i < n; ++i) {
    int k, l;
    cin >> k >> l;
    if (k >= l) {
      sum += l;
      continue;
    }
    S.push_back({k, l});
  }
  sort(S.begin(), S.end(), pred);
  int sz = S.size();
  for (int i = 0; i < sz; ++i) {
    if (i < c)
      sum += min(S[i].first * 2, S[i].second);
    else
      sum += min(S[i].first, S[i].second);
  }
  cout << sum << '\n';
  return 0;
}
