#include <bits/stdc++.h>
using namespace std;
bool mark[1000002];
int main() {
  int n, f;
  scanf("%d %d", &n, &f);
  vector<pair<int, int> > v;
  v.push_back(make_pair(0, 0));
  int product[n + 1], client[n + 1];
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &product[i], &client[i]);
    if (product[i] > client[i])
      sum += client[i];
    else {
      sum += product[i];
      int exClient = client[i] - product[i];
      int c = min(exClient, product[i]);
      v.push_back(make_pair(c, i));
    }
  }
  sort(v.rbegin(), v.rend());
  int len = v.size();
  for (int i = 0; (i < f && i < len); i++) {
    sum += v[i].first;
  }
  cout << sum << endl;
  return 0;
}
