#include <bits/stdc++.h>
using namespace std;
void deb() { cerr << endl; }
template <typename T, typename... t>
void deb(T a, t... b) {
  cerr << a << " ";
  deb(b...);
}
int64_t dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int64_t dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
void max_self(int64_t& x, int64_t y) { x = max(x, y); }
template <class T>
T roof(T x, T y) {
  return (x + y - 1) / y;
}
template <class T>
T lcm(T a, T b) {
  return a * b / __gcd(a, b);
}
int64_t qpow(int64_t x, int64_t n) {
  int64_t r = 1;
  for (; n; n >>= 1) {
    if (n & 1) (r = r * x);
    (x = x * x);
  }
  return r;
}
void done(int64_t cases) {
  int64_t n, k;
  cin >> n >> k;
  vector<pair<int64_t, int64_t> > v(n);
  vector<int64_t> store;
  int64_t ans = 0;
  for (auto& [x, y] : v) {
    cin >> x >> y;
    ans += min(x, y);
    store.push_back(min(2 * x, y) - min(x, y));
  }
  sort((store).begin(), (store).end());
  int64_t cnt = 0;
  while (cnt < k) {
    ans += store.back();
    cnt++;
    store.pop_back();
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(15);
  int64_t tt;
  tt = 1;
  for (int64_t i = 1; i <= tt; ++i) {
    done(i);
  }
  return 0;
}
