#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
vector<int> g[N];
bool vis[N] = {0};
int a[N];
bool ifprime(long long x) {
  if (x == 1 || x == 2) return true;
  if (x % 2 == 0) return false;
  for (long long i = 3; i <= sqrt(x); i += 2) {
    if (x % i == 0) return false;
  }
  return true;
}
int alp[26] = {0};
long long fsum(string s) {
  int x = s.size();
  long long ans = 0;
  for (int i = 0; i < x; ++i) ans += (s[i] - '0');
  return ans;
}
int first_div(int n) {
  for (int i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) return i;
  }
  return n;
}
int dfs(int x) {
  vis[x]++;
  int val = a[x];
  for (int q : g[x]) {
    if (vis[q]) continue;
    val = min(val, dfs(q));
  }
  return val;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  clock_t start, end;
  start = clock();
  int t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int a[n];
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      sum += min(x, y);
      a[i] = min(2 * x, y) - min(x, y);
    }
    sort(a, a + n, greater<int>());
    for (int i = 0; i < k; ++i) sum += a[i];
    cout << sum;
  }
  end = clock();
  return 0;
}
