#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct day {
  ll k, l, can;
  bool operator<(const day &r) const { return can > r.can; }
  void print() { cout << k << " " << l << " " << can << "\n"; }
};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ll n, f;
  cin >> n >> f;
  vector<day> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].k >> a[i].l;
    ll kk = a[i].k, ll = a[i].l;
    if (kk >= ll) {
      a[i].can = 0;
      a[i].k = a[i].l;
    } else {
      if (2 * kk <= ll) {
        a[i].can = kk;
      } else {
        a[i].can = ll - kk;
      }
    }
  }
  sort(a.begin(), a.end());
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    (i < f) ? sum += a[i].k + a[i].can : sum += a[i].k;
  }
  cout << sum;
  return 0;
}
