#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  pair<int, int> group[100000];
  for (int i = 0; i < n; i++) {
    int s, p;
    cin >> s >> p;
    group[i] = make_pair(min(2 * s, p) - min(s, p), min(s, p));
  }
  sort(group, group + n);
  long long count = 0;
  for (int i = n - 1; i >= n - k; i--) {
    count += group[i].first + group[i].second;
  }
  for (int i = n - k - 1; i >= 0; i--) {
    count += group[i].second;
  }
  cout << count;
}
