#include <bits/stdc++.h>   using namespace std;   long long n, f, a, b;   vector<long long> V;   long long ans;   int main() {     scanf( %lld %lld , &n, &f);     for (int i = 1; i <= n; i++) {       scanf( %lld %lld , &a, &b);       if (a >= b) {         V.push_back(0);         ans += b;       } else {         if (a * 2 <= b) {           V.push_back(a);         } else {           V.push_back(b - a);         }         ans += a;       }     }     sort(V.begin(), V.end());     reverse(V.begin(), V.end());     for (int i = 0; i < f; i++) {       ans += V[i];     }     cout << ans << endl;     return 0;   }   