// Slower C++ solution:
//Solution for aoj:0530 Pyon-Pyon River Crossing

#include<iostream>

#include<algorithm>

#include<vector>

using namespace std;

const int INF = 10000000000, MAX_N = 150;

typedef pair<int, int> P;

int n, m, ans;

int dp[MAX_N + 3][1001][76];

P stone, stone2;

vector<P> Stone[151]; //first:??????second:???????????????

int main(){

	while (cin >> n >> m){

		if (!n&&!m)

			return 0;

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

			Stone[i].clear();

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

			int a, b, c;

			cin >> c;

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

				cin >> a >> b;

				Stone[i].push_back(P(a, b));

			}

		}

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

			for (int j = 1; j <= 1000; j++){

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

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

				}

			}

		}

		for (int i = 0; i < Stone[2].size(); i++){

			stone = Stone[2][i];

			dp[2][stone.first][m] = INF;

		}

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

			for (int j = 0; j < Stone[i].size(); j++){

				stone = Stone[i][j];

				for (int k = 0; k <= 75; k++)

					dp[i][stone.first][k] = INF;

			}

		}

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

			for (int j = 0; j < Stone[i].size(); j++){

				stone = Stone[i][j];

				for (int k = 0; k < Stone[i + 1].size(); k++){

					stone2 = Stone[i + 1][k];

					for (int l = m; l >= m - i / 2; l--){

						if (l < 0)

							break;

						dp[i + 1][stone2.first][l] = min(dp[i + 1][stone2.first][l], (stone.second + stone2.second)*abs(stone.first - stone2.first) + dp[i][stone.first][l]);

					}

				}

				for (int k = 0; k < Stone[i + 2].size(); k++){

					if (i + 2 > n)

						break;

					stone2 = Stone[i + 2][k];

					for (int l = m - 1; l >= m - (i + 2) / 2; l--){

						if (l < 0)

							break;

						dp[i + 2][stone2.first][l] = min(dp[i + 2][stone2.first][l], (stone.second + stone2.second) * abs(stone.first - stone2.first) + dp[i][stone.first][l + 1]);

					}

				}

			}

		}

		ans = INF;

		for (int i = 0; i < Stone[n].size(); i++){

			stone = Stone[n][i];

			for(int j = 0; j <= m; j++)

			  ans = min(dp[n][stone.first][j], ans);

		}

		for (int i = 0; i < Stone[n - 1].size(); i++){

			stone = Stone[n - 1][i];

			for(int j = 1; j <= m; j++)

			  ans = min(dp[n - 1][stone.first][j], ans);

		}

		cout << ans << endl;

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.2844306103329495x):
#include <bits/stdc++.h>

using namespace std;

#define F first

#define S second

typedef pair<int, int> P;

int n, m;

int dp[80][200][20], kosu[1600];

P stone[1600][20];

int main()

{

	while(cin >> n >> m && n)

	{

		for(int i = 0; i < n; i++)

		{

			cin >> kosu[i];

			for(int j = 0; j < kosu[i]; j++)

			{

				cin >> stone[i][j].F >> stone[i][j].S;

			}

		}

		for(int i = 0; i <= m; i++)

			for(int j = 0; j < n; j++)

				for(int k = 0; k < kosu[j]; k++)

					dp[i][j][k] = 1 << 30;

				for(int i = 0; i < kosu[0]; i++)

					dp[0][0][i] = 0;

				for(int i = 0; i < kosu[1]; i++)

					dp[1][1][i] = 0;

				for(int i = 0; i < n - 1; i++)

				{

					for(int j = 0; j < kosu[i]; j++)

					{

						for(int k = 0; k < kosu[i + 1]; k++)

						{

							for(int l = 0; l <= m; l++)

							{

								if(dp[l][i][j] < 1 << 30)

									dp[l][i + 1][k] = min((stone[i + 1][k].S + stone[i][j].S) * abs(stone[i + 1][k].F - stone[i][j].F) + dp[l][i][j], dp[l][i + 1][k]);

							}

						}

						if(i + 2 < n)

						{

							for(int k = 0; k < kosu[i + 2]; k++)

							{

								for(int l = 0; l < m; l++)

								{



									if(dp[l][i][j] < 1 << 30)

									{

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

									}

								}

							}

						}

					}

				}

				int ans = INT_MAX;

				for(int i = 0; i <= m; i++)

					for(int j = 0; j < kosu[n - 1]; j++)

						ans = min(ans, dp[i][n - 1][j]);

					for(int i = 0; i < m; i++)

						for(int j = 0; j < kosu[n - 2]; j++)

							ans = min(ans, dp[i][n - 2][j]);

						cout << ans << endl;

					}

				}