#include <bits/stdc++.h>   using namespace std;   int main() {     int n, f, i, j;     cin >> n >> f;     long long ans(0), k, l, mini;     vector<pair<long long, long long> > v, v1;     for (i = 0; i < n; i++) {       cin >> k >> l;       v.push_back(make_pair(k, l));     }     for (i = 0; i < n; i++) {       v1.push_back(make_pair(           min(2 * v[i].first, v[i].second) - min(v[i].first, v[i].second), i));     }     sort(v1.begin(), v1.end(), greater<pair<long long, long long> >());     for (i = 0; i < f; i++) {       mini = min(2 * v[v1[i].second].first, v[v1[i].second].second);       ans += mini;       v[v1[i].second].first = -1;     }     for (i = 0; i < n; i++) {       if (v[i].first != -1) ans += min(v[i].first, v[i].second);     }     cout << ans;     return 0;   }   