#include <bits/stdc++.h>
using namespace std;
int n,k;
long long a[100005],b[100005];
long long f(long long x)
{
long long s=0;
int i;
long long y=0;
vector<long long>v;
for(i=0;i<n;i++)
{
long long aa=abs(a[i]-x)+b[i];
v.push_back(aa);
}
sort(v.begin(),v.end());
for(i=0;i<k;i++)
{
s+=v[i];
}
return s;
}
int main()
{
cin>>n>>k;
int i;
for(i=0;i<n;i++)
{
cin>>a[i]>>b[i];
}
long long ans=-1;
long long low=1,high=1e8;
while(low<=high)
{
long long mid=(low+high)/2;
long long int u1=f(mid-1);
long long int u2=f(mid);
long long int u3=f(mid+1);
if(u1<=u2&&u2<=u3)
{
low=mid+1;
}
else if(u1>=u2&&u2>=u3)
{
high=mid-1;
}
else if(u2<=u1&&u2<=u3)
{
ans=u2;
break;
}
}
cout<<ans<<endl;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBuLGs7CmxvbmcgbG9uZyBhWzEwMDAwNV0sYlsxMDAwMDVdOwpsb25nIGxvbmcgZihsb25nIGxvbmcgeCkKewogICAgbG9uZyBsb25nIHM9MDsKICAgIGludCBpOwogICAgbG9uZyBsb25nIHk9MDsKICAgIHZlY3Rvcjxsb25nIGxvbmc+djsKICAgIGZvcihpPTA7aTxuO2krKykKICAgIHsKICAgICAgICBsb25nIGxvbmcgYWE9YWJzKGFbaV0teCkrYltpXTsKICAgICAgICB2LnB1c2hfYmFjayhhYSk7CiAgICB9CiAgICBzb3J0KHYuYmVnaW4oKSx2LmVuZCgpKTsKICAgIGZvcihpPTA7aTxrO2krKykKICAgIHsKICAgICAgICBzKz12W2ldOwogICAgfQogICAgcmV0dXJuIHM7Cn0KaW50IG1haW4oKQp7CiAgICBjaW4+Pm4+Pms7CiAgICBpbnQgaTsKICAgIGZvcihpPTA7aTxuO2krKykKICAgIHsKICAgICAgICBjaW4+PmFbaV0+PmJbaV07CiAgICB9CiAgICBsb25nIGxvbmcgYW5zPS0xOwogICAgbG9uZyBsb25nIGxvdz0xLGhpZ2g9MWU4OwogICAgd2hpbGUobG93PD1oaWdoKQogICAgewogICAgICAgIGxvbmcgbG9uZyBtaWQ9KGxvdytoaWdoKS8yOwogICAgICAgIGxvbmcgbG9uZyBpbnQgdTE9ZihtaWQtMSk7CiAgICAgICAgbG9uZyBsb25nIGludCB1Mj1mKG1pZCk7CiAgICAgICAgbG9uZyBsb25nIGludCB1Mz1mKG1pZCsxKTsKICAgICAgICBpZih1MTw9dTImJnUyPD11MykKICAgICAgICB7CiAgICAgICAgICAgIGxvdz1taWQrMTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZih1MT49dTImJnUyPj11MykKICAgICAgICB7CiAgICAgICAgICAgIGhpZ2g9bWlkLTE7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYodTI8PXUxJiZ1Mjw9dTMpCiAgICAgICAgewogICAgICAgICAgICBhbnM9dTI7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgIH0KICAgIGNvdXQ8PGFuczw8ZW5kbDsKfQo=