#include <bits/stdc++.h>
using namespace std;
pair<long long, pair<long long, long long> > p[100009];
int comp(pair<long long, pair<long long, long long> > a,
         pair<long long, pair<long long, long long> > b) {
  return a.first > b.first;
}
int main() {
  int n, k, sum = 0;
  long long ans = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> p[i].second.first >> p[i].second.second;
    p[i].first = min(p[i].second.first * 2, p[i].second.second) -
                 min(p[i].second.first, p[i].second.second);
    ans += min(p[i].second.first, p[i].second.second);
  }
  sort(p + 1, p + n + 1, comp);
  for (int i = 1; i <= k; i++) {
    ans += p[i].first;
  }
  cout << ans;
}
