// Original C++ solution (slower):
#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <string>

#include <algorithm>

#include <vector>

#include <queue>

#include <stack>

#include <functional>

#include <iostream>

#include <map>

#include <set>

using namespace std;

typedef pair<int,int> P;

typedef pair<int,P> P1;

typedef pair<P,P> P2;

#define pu push

#define pb push_back

#define mp make_pair

#define eps 1e-7

#define INF 2000000000

int n,m;

int stone[155][11][2];

int dp[155][11][76];

int num[155];

int cost(int a,int b,int c){

	if(a==n || (a==n-1 && c<m)){

		return 0;

	}

	if(dp[a][b][c]!=-1) return dp[a][b][c];

	int mini=INF;

	for(int i=1;i<=num[a+1];i++){

		mini=min(mini,(stone[a+1][i][1]+stone[a][b][1])*abs(stone[a][b][0]-stone[a+1][i][0])+cost(a+1,i,c));

	}

	if(c!=m){

	for(int i=1;i<=num[a+2];i++){

		mini=min(mini,(stone[a+2][i][1]+stone[a][b][1])*abs(stone[a][b][0]-stone[a+2][i][0])+cost(a+2,i,1+c));

	}

	}

	return dp[a][b][c]=mini;

}

int main(){

	while(scanf("%d %d",&n,&m) && n){

		for(int i=1;i<=n;i++){

			scanf("%d",&num[i]);

			for(int g=1;g<=num[i];g++){

				scanf("%d %d",&stone[i][g][0],&stone[i][g][1]);

			}

		}

		memset(dp,-1,sizeof(dp));

		int ans=INF;

		for(int i=1;i<=num[1];i++){

			ans=min(ans,cost(1,i,0));

		}

		if(m>0){

			for(int i=1;i<=num[2];i++){

				ans=min(ans,cost(2,i,1));

			}

		}

		printf("%d\n",ans);

	}

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <string>

#include <algorithm>

#include <vector>

#include <queue>

#include <stack>

#include <functional>

#include <iostream>

#include <map>

#include <set>

using namespace std;

typedef pair<int,int> P;

typedef pair<int,P> P1;

typedef pair<P,P> P2;

#define pu push

#define pb push_back

#define mp make_pair

#define eps 1e-7

#define INF 2000000000

int n,m;

int stone[155][11][2];

int dp[155][11][76];

int num[155];

int main(){

	while(scanf("%d %d",&n,&m) && n){

		for(int i=1;i<=n;i++){

			scanf("%d",&num[i]);

			for(int g=1;g<=num[i];g++){

				scanf("%d %d",&stone[i][g][0],&stone[i][g][1]);

			}

		}

		for(int i=0;i<155;i++){

			for(int j=0;j<11;j++){

				for(int k=0;k<=m;k++){

					dp[i][j][k]=INF;

				}

			}

		}

		for(int j=1;j<=num[1];j++){

			for(int k=0;k<=m;k++){

				dp[1][j][k]=0;

			}

		}

		for(int j=1;j<=num[2];j++){

			for(int k=1;k<=m;k++){

				dp[2][j][k]=0;

			}

			for(int y=1;y<=num[1];y++){

				dp[2][j][0]=min(dp[2][j][0],dp[1][y][0]+abs(stone[1][y][0]-stone[2][j][0])*(stone[1][y][1]+stone[2][j][1]));

			}

		}

		int ans=INF;

		for(int i=3;i<=n;i++){

			for(int j=1;j<=num[i];j++){

				for(int k=0;k<=m;k++){

					for(int g=1;g<=num[i-1];g++){

						dp[i][j][k]=min(dp[i][j][k],dp[i-1][g][k]+abs(stone[i][j][0]-stone[i-1][g][0])*(stone[i][j][1]+stone[i-1][g][1]));

					}

					if(k!=0){

						for(int l=1;l<=num[i-2];l++){

							dp[i][j][k]=min(dp[i][j][k],dp[i-2][l][k-1]+abs(stone[i][j][0]-stone[i-2][l][0])*(stone[i][j][1]+stone[i-2][l][1]));

						}

					}

				}

			}

		}

		int res=INF;

		for(int j=1;j<=num[n];j++){

			for(int k=0;k<=m;k++){

			res=min(res,dp[n][j][k]);

			}

		}

		for(int j=1;j<=num[n-1];j++){

			for(int k=0;k<m;k++){

			res=min(res,dp[n-1][j][k]);

			}

		}

		printf("%d\n",res);

	}

}

// Fastest known solution for this problem: