#include <bits/stdc++.h>

using namespace std;

int N, M;
int MapData[152][1002];
vector<pair<int, int> > StoneInfo[152];
int DpSum[152][1002][78];

const int INF = 999999999;

void solve() {
	int curRowStone, curCol, cost, minSum;

	curRowStone = StoneInfo[1].size();
	for (int i = 0; i < curRowStone; ++i) {
		curCol = StoneInfo[1][i].first;
		DpSum[1][curCol][0] = 0;
	}

	curRowStone = StoneInfo[2].size();
	for (int i = 0; i < curRowStone; ++i) {
		curCol = StoneInfo[2][i].first;
		DpSum[2][curCol][1] = 0;
	}

	for (int i = 1; i < N; ++i) {
		for (int j = 1; j < 1002; ++j) {
			for (int k = 0; k <= M; ++k) {
				if (DpSum[i][j][k] == INF) {
					continue;
				}

				curRowStone = StoneInfo[i + 1].size();
				for (int t = 0; t < curRowStone; ++t) {
					curCol = StoneInfo[i + 1][t].first;
					cost = (MapData[i][j] + StoneInfo[i + 1][t].second) * abs(j - curCol);
					DpSum[i + 1][curCol][k] = min(DpSum[i + 1][curCol][k], DpSum[i][j][k] + cost);
				}

				if (k == M || i == N - 1) {
					continue;
				}
				curRowStone = StoneInfo[i + 2].size();
				for (int t = 0; t < curRowStone; ++t) {
					curCol = StoneInfo[i + 2][t].first;
					cost = (MapData[i][j] + StoneInfo[i + 2][t].second) * abs(j - curCol);
					DpSum[i + 2][curCol][k + 1] = min(DpSum[i + 2][curCol][k + 1], DpSum[i][j][k] + cost);
				}
			}
		}
	}

	minSum = INF;
	for (int i = 0; i < 1002; ++i) {
		for (int k = 0; k <= M; ++k) {
			minSum = min(minSum, DpSum[N][i][k]);
		}
	}
	for (int i = 0; i < 1002; ++i) {
		for (int k = 0; k < M; ++k) {
			minSum = min(minSum, DpSum[N - 1][i][k]);
		}
	}
	cout << minSum << endl;
}

int main() {
	int k, col, value;

	while (cin >> N >> M, N) {
		for (int i = 0; i < 152; ++i) {
			StoneInfo[i].clear();
			for (int j = 0; j < 1002; ++j) {
				MapData[i][j] = INF;
			}
		}
		for (int i = 1; i <= N; ++i) {
			cin >> k;
			for (int j = 0; j < k; ++j) {
				cin >> col >> value;
				MapData[i][col] = value;
				StoneInfo[i].push_back({ col,value });
			}
		}
		//fill_n(&DpSum[0][0][0], N * 1002 * M, INF);
		for (int i = 0; i < 152; ++i) {
			for (int j = 0; j < 1002; ++j) {
				for (int k = 0; k < 78; ++k) {
					DpSum[i][j][k] = INF;
				}
			}
		}
		solve();
	}

	return 0;
}
