#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int INF = 1000000000;
int n,m,dp[200][20][100],gc[200];
vector<P> tobu[200];
int main(){
	while(1){
		scanf("%d%d",&n,&m);
		if(n + m == 0)break;
		for(int i = 0;i <= n;i++){
			tobu[i].clear();
		}
		for(int i = 1;i <= n;i++){
			scanf("%d",&gc[i]);
			for(int j = 0;j < gc[i];j++){
				int x,d;
				scanf("%d%d",&x,&d);
				tobu[i].push_back(P(x,d));
			}
		}
		for(int i = 0;i < 200;i++){
			for(int j = 0;j < 20;j++){
				for(int k = 0;k < 100;k++){
					dp[i][j][k] = INF;
				}
			}
		}
		for(int i = 0;i < 20;i++){
			dp[1][i][m] = 0;
			if(m != 0){
				dp[2][i][m-1] = 0;
			}
		}

		for(int i = 1;i <= n;i++){
			for(int j = 0;j < gc[i];j++){
				int nx = tobu[i][j].first,nd = tobu[i][j].second;
				for(int k = 0;k <= m;k++){
					for(int l = 0;l < gc[i+1];l++){
						int tx = tobu[i+1][l].first,td = tobu[i+1][l].second;
						dp[i+1][l][k] = min(dp[i+1][l][k],dp[i][j][k]+(nd+td)*abs(nx-tx));
					}
					if(k == 0)continue;
					for(int l = 0;l < gc[i+2];l++){
						int tx = tobu[i+2][l].first,td = tobu[i+2][l].second;
						dp[i+2][l][k-1] = min(dp[i+2][l][k-1],dp[i][j][k]+(nd+td)*abs(nx-tx));
					}
				}
			}
		}
		int ans = INF;

		for(int i = 0;i < 20;i++){
			for(int j = 0;j <= m;j++){
				ans = min(ans,dp[n][i][j]);
			}
		}
		for(int i = 0;i < 20;i++){
			for(int j = 1;j <= m;j++){
				ans = min(ans,dp[n-1][i][j]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
