#include <bits/stdc++.h>
using namespace std;
int n, f, plan[100005][2];
long long sum;
priority_queue<int> pq;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> f;
  for (int i = 0; i < n; i++) {
    cin >> plan[i][0] >> plan[i][1];
  }
  for (int i = 0; i < n; i++) {
    if (plan[i][1] > plan[i][0]) {
      if (2 * plan[i][0] <= plan[i][1])
        pq.push(plan[i][0]);
      else
        pq.push(plan[i][1] - plan[i][0]);
      sum += plan[i][0];
    } else
      sum += plan[i][1];
  }
  while (pq.size() && f--) {
    sum += pq.top();
    pq.pop();
  }
  cout << sum << endl;
  return 0;
}
