#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<29)

typedef pair<int, int> pii;

int dp[150][10][80]; //[i][j][k] i???????????§??§(i???,j??????)????????§?????????k????????£????????§????????¨??????????°????
vector<pii> stone[150]; // x[0-indexed], suberi
int n, m;

int main() {
	while (cin >> n >> m, n || m) {
		fill(dp[0][0], dp[n][0], INF);
		REP(i, n) stone[i].clear();
		
		REP(i, n) {
			int k;
			scanf("%d", &k);
			REP(j, k) {
				int a, b;
				scanf("%d %d", &a, &b);
				stone[i].push_back(pii(a, b));
			}
		}
		
		REP(i, stone[0].size()) dp[0][i][m] = 0;
		if (m != 0) REP(i, stone[1].size()) dp[1][i][m - 1] = 0;
		
		REP(i, n - 1) REP(j, stone[i].size()) REP(k, m + 1) {
			pii &from = stone[i][j];
			
			// 1????£???°???
			if (i < n - 2 && k > 0) {
				REP(l, stone[i + 2].size()) {
					pii &to = stone[i + 2][l];
					int cost = (from.second + to.second) * abs(from.first - to.first);
					dp[i + 2][l][k - 1] = min(dp[i + 2][l][k - 1], dp[i][j][k] + cost);
				}
			}
			
			REP(l, stone[i + 1].size()) {
				pii &to = stone[i + 1][l];
				int cost = (from.second + to.second) * abs(from.first - to.first);
				dp[i + 1][l][k] = min(dp[i + 1][l][k], dp[i][j][k] + cost);
			}
		}
		
		int ans = INF;
		REP(i, stone[n - 1].size()) REP(j, m + 1) ans = min(ans, dp[n - 1][i][j]);
		REP(i, stone[n - 2].size()) FOR(j, 1, m + 1) ans = min(ans, dp[n - 2][i][j]);
		cout << ans << endl;
	}
	return 0;
}