#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long int n, f;
    cin >> n >> f;
    long long int ans = 0;
    vector<pair<long long int, pair<long long int, long long int> > > v;
    for (long long int i = 0; i < n; ++i) {
      long long int k, l;
      cin >> k >> l;
      if (k >= l) {
        ans += l;
        continue;
      }
      int kp;
      if (2 * k > l)
        kp = l - k;
      else
        kp = k;
      v.push_back(make_pair(kp, make_pair(k, l)));
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for (long long int i = 0; i < v.size(); i++) {
      if (f)
        ans += v[i].second.first + v[i].first;
      else
        ans += v[i].second.first;
      if (f != 0) f--;
    }
    cout << ans;
  }
  return 0;
}
