#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
	int n,m;
	int k[150]={};
	int x[150][10]={};
	int s[150][10]={};
	int mr[150][10][77]={};
	int r,ar;
	while(1){
		cin >> n >> m;
		if(n==0){return 0;}
		for(int i=0;i<n;i++){
			cin >> k[i];
			for(int j=0;j<k[i];j++){
				cin >> x[i][j] >> s[i][j];
			}
		}
		for(int i=0;i<k[n-1];i++){
			mr[n-1][i][0]=0;
			mr[n-1][i][1]=0;
		}
		for(int i=0;i<k[n-2];i++){
			mr[n-2][i][0]=0;
		}
		for(int i=n-2;i>=0;i--){
			//cout << "i "<< i << endl;
			for(int am=max(0,m-(i+1)/2);am<=(n-i)/2 && am<=m && !(i==n-2 && am==1);am++){
				// << "am " << am << " ";
				for(int j=0;j<k[i];j++){
					mr[i][j][am]=-1;
					for(int l=0;l<k[i+1];l++){
						int am2=min(am,(n-i-1)/2);
						r=mr[i+1][l][am2]+(s[i][j]+s[i+1][l])*abs(x[i][j]-x[i+1][l]);
						if(mr[i+1][l][am2]>=0 && (r<mr[i][j][am] || mr[i][j][am]==-1)){
							mr[i][j][am]=r;
						}
					}
					if(am>0){
						for(int l=0;l<k[i+2];l++){
							//if(mr[i+2][l][am-1]==0){cout <<"i:"<<i <<" j:"<< j << " l:"<<l<<" am:"<<am <<endl;}
							r=mr[i+2][l][am-1]+(s[i][j]+s[i+2][l])*abs(x[i][j]-x[i+2][l]);
							if(mr[i+2][l][am-1]>=0 && (r<mr[i][j][am] || mr[i][j][am]==-1)){
								mr[i][j][am]=r;
							}
						}
					}
					//cout << "i:" << i << " j:" << j << " am:" <<am << " mr:" << mr[i][j][am] << endl;
				//cout << " "<<mr[i][j][am] ;
				}
			//cout << endl;
			}
		}
		int mar=-1;
		for(int i=0;i<k[0];i++){
			ar=mr[0][i][m];
			if(ar < mar || mar==-1){
				mar=ar;
			}
		}
		if(m>1){
			for(int i=0;i<k[1];i++){
				ar=mr[1][i][m-1];
				if(ar < mar|| mar==-1){
					mar=ar;
				}
			}
		}
		cout << mar << endl;
	}
}