传送门
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define P pair<int,int>
const int N=1e4;
const int mod=1e9+7;
void read(int &a)
{
a=0;
int d=1;
char ch;
while(ch=getchar(),ch>'9'||ch<'0')
if(ch=='-')
d=-1;
a=ch-'0';
while(ch=getchar(),ch>='0'&&ch<='9')
a=a*10+ch-'0';
a*=d;
}
void write(int x)
{
if(x<0)
putchar(45),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
}
int f[55][55][2],a[55],sum[55],loc[55];
int main()
{
int n,m;
read(n);
read(m);
for(re int i=1;i<=n;i++)
{
read(loc[i]);
read(a[i]);
}
for(re int i=1;i<=n;i++)
sum[i]=a[i]+sum[i-1];
memset(f,0x3f,sizeof(f));
f[m][m][0]=0,f[m][m][1]=0;
for(re int i=m;i<=n;i++)
for(re int j=i-1;j>=1;j--)
{
f[j][i][0]=min(f[j+1][i][0]+(loc[j+1]-loc[j])*(sum[n]+sum[j]-sum[i]),f[j+1][i][1]+(loc[i]-loc[j])*(sum[n]+sum[j]-sum[i]));
f[j][i][1]=min(f[j][i-1][1]+(loc[i]-loc[i-1])*(sum[n]+sum[j-1]-sum[i-1]),f[j][i-1][0]+(loc[i]-loc[j])*(sum[n]-sum[i-1]+sum[j-1]));
}
cout<<min(f[1][n][0],f[1][n][1]);
return 0;
}