#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
ll a[100005],b[100005];
ll f(ll x)
{
ll s=0ll;
int i;
vector<ll>v;
for(i=0;i<n;i++)
{
ll 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];
}
ll ok=-1e9,ng=1e9;
while(abs(ok-ng)>1)
{
ll mi=(ok+ng)/2;
ll u1=f(mi);
ll u2=f(mi+1);
if(u1>=u2)
{
ok=mi;
}
else
{
ng=mi;
}
}
cout<<f(ok+1)<<endl;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKaW50IG4sazsKbGwgYVsxMDAwMDVdLGJbMTAwMDA1XTsKbGwgZihsbCB4KQp7CiAgICBsbCBzPTBsbDsKICAgIGludCBpOwogICAgdmVjdG9yPGxsPnY7CiAgICBmb3IoaT0wO2k8bjtpKyspCiAgICB7CiAgICAgICAgbGwgYWE9YWJzKGFbaV0teCkrYltpXTsKICAgICAgICB2LnB1c2hfYmFjayhhYSk7CiAgICB9CiAgICBzb3J0KHYuYmVnaW4oKSx2LmVuZCgpKTsKICAgIGZvcihpPTA7aTxrO2krKykKICAgIHsKICAgICAgICBzKz12W2ldOwogICAgfQogICAgcmV0dXJuIHM7IAp9CmludCBtYWluKCkKewogICAgY2luPj5uPj5rOwogICAgaW50IGk7CiAgICBmb3IoaT0wO2k8bjtpKyspCiAgICB7CiAgICAgICAgY2luPj5hW2ldPj5iW2ldOwogICAgfQogICAgbGwgb2s9LTFlOSxuZz0xZTk7CiAgICB3aGlsZShhYnMob2stbmcpPjEpCiAgICB7CiAgICAgICAgbGwgbWk9KG9rK25nKS8yOwogICAgICAgIGxsIHUxPWYobWkpOwogICAgICAgIGxsIHUyPWYobWkrMSk7CiAgICAgICAgaWYodTE+PXUyKQogICAgICAgIHsKICAgICAgICAgICAgb2s9bWk7CiAgICAgICAgfQogICAgICAgIGVsc2UgCiAgICAgICAgewogICAgICAgICAgICBuZz1taTsKICAgICAgICB9CiAgICB9CiAgICBjb3V0PDxmKG9rKzEpPDxlbmRsOwp9