/*input
4 1
0 2
0 3
3 5
0 6
*/
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define F(i,a,b) for(ll i = a; i <= b; i++)
#define RF(i,a,b) for(ll i = a; i >= b; i--)
#define pii pair<ll,ll>
#define PI 3.14159265358979323846264338327950288
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
ll BIT[200005];
void update(ll id,ll val) {
for(ll i=id;i<=200000;i+=i&-i) BIT[i]+=val;
}
ll query(ll id) {
ll sum=0;
for(ll i=id;i>0;i-=i&-i) sum+=BIT[i];
return sum;
}
ll arr[200005];
int main()
{
std::ios::sync_with_stdio(false);
ll n,f;
cin>>n>>f;
ll ans = 0;
F(i,0,n-1)
{
ll k,l;
cin>>k>>l;
ll in = min(k,l);
ans = ans + min(k,l);
k = 2ll*k;
ll fin = min(k,l);
arr[i] = fin - in;
}
sort(arr,arr+n);
ll i=n-1;
while(f--)
{
ans += arr[i];
i--;
}
cout<<ans<<endl;
return 0;
}
LyppbnB1dAo0IDEKMCAyCjAgMwozIDUKMCA2CiovCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgojaW5jbHVkZTxzdGRpby5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIEYoaSxhLGIpIGZvcihsbCBpID0gYTsgaSA8PSBiOyBpKyspCiNkZWZpbmUgUkYoaSxhLGIpIGZvcihsbCBpID0gYTsgaSA+PSBiOyBpLS0pCiNkZWZpbmUgcGlpIHBhaXI8bGwsbGw+CiNkZWZpbmUgUEkgMy4xNDE1OTI2NTM1ODk3OTMyMzg0NjI2NDMzODMyNzk1MDI4OAojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGZmIGZpcnN0CiN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