#include <bits/stdc++.h>
using namespace std;
int v[26];
int main() {
  int n, f;
  cin >> n >> f;
  long long ans = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    ans += min(a, b);
    v.push_back(max(0, min(b - a, a)));
  }
  sort(v.begin(), v.end());
  for (int i = n - 1; i >= n - f; i--) {
    ans += v[i];
  }
  cout << ans;
}
