#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main() {
	int row, jump;
	int dp[151][11][76];
	int val[151][11];
	int Size[151];
	int num[151][11];

	while (cin >> row >> jump, row)
	{
		
		for (int i = 0; i < row; i++) {
			cin >> Size[i];
			for (int j = 0; j < Size[i]; j++) {
				cin >> num[i][j] >> val[i][j];
			}
		}

		memset(dp, 0x7f, sizeof(dp));			//初期化
		for (int i = 0; i < Size[0]; i++)		//岸からのジャンプ
			dp[0][i][0] = 0;
		for (int i = 0; i < Size[1]; i++)
			dp[1][i][1] = 0;

		for (int i = 0; i < row-1; i++) {
			for (int j = 0; j < Size[i]; j++) {
				for (int k = 0; k < Size[i + 1]; k++) {
					int risk = (val[i][j] + val[i + 1][k])*abs(num[i][j] - num[i+1][k]);
					for (int m = 0; m <= jump; m++)
						dp[i + 1][k][m] = min(dp[i + 1][k][m], dp[i][j][m] + risk);
				}
				if (i == row - 2)continue;
				for (int k = 0; k < Size[i + 2]; k++) {
					int risk = (val[i][j] + val[i + 2][k])*abs(num[i][j] - num[i + 2][k]);
					for (int m = 0; m < jump; m++)
						dp[i + 2][k][m+1] = min(dp[i + 2][k][m+1], dp[i][j][m] + risk);
				}
			}

		}
		int Min = 0x7f7f7f7f;

		for (int i = 0; i < Size[row - 1]; i++)
			for (int j = 0; j <= jump; j++) {
				Min = min(Min, dp[row - 1][i][j]);

			}
		for (int i = 0; i < Size[row - 2]; i++)
			for (int j = 0; j < jump; j++)
				Min = min(Min, dp[row - 2][i][j]);
		
		cout << Min << endl;
	}
	return 0;
}
