#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long, long long> p1, pair<long long, long long> p2) {
  return min(2 * p1.first, p1.second) - min(p1.first, p1.second) >
         min(2 * p2.first, p2.second) - min(p2.first, p2.second);
}
int main() {
  int n, f;
  cin >> n >> f;
  vector<pair<long long, long long> > goods;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long k, l;
    cin >> k >> l;
    goods.push_back(make_pair(k, l));
  }
  sort(goods.begin(), goods.end(), cmp);
  int i = 0;
  for (i = 0; i < f; i++) {
    ans += min(2 * goods[i].first, goods[i].second);
  }
  for (; i < n; i++) {
    ans += min(goods[i].first, goods[i].second);
  }
  cout << ans;
  return 0;
}
