#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T power(T base, int p) {
  T f = 1;
  for (int i = 1; i <= p; i++) f *= base;
  return f;
}
template <typename T>
string NumberToString(T Number) {
  ostringstream ss;
  ss << Number;
  return ss.str();
}
int setbit(int N, int pos) { return N = N | (1 << pos); }
int resetbit(int N, int pos) { return N = N & ~(1 << pos); }
bool checkbit(int N, int pos) { return (bool)(N & (1 << pos)); }
int noofsetbits(int N) { return __builtin_popcount(N); }
vector<long long int> lav;
int main() {
  int n;
  int f;
  while (cin >> n >> f) {
    lav.clear();
    long long int sum = 0;
    for (int i = 1; i <= n; i++) {
      long long int k, l;
      cin >> k >> l;
      sum += min(l, k);
      lav.push_back(min(2 * k, l) - min(k, l));
    }
    sort(lav.rbegin(), lav.rend());
    for (int i = 0; i < f; i++) {
      sum += lav[i];
    }
    cout << sum << endl;
  }
}
