#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define INF (2000000001)
#define X first
#define D second
typedef pair<int,int> P;
int N,M;
vector<P> R[152];
int dp[151][11][1001];
inline int ab(int a){ return a>0?a:-a; }
int solve(int no,int id,int m){
  if( no >= N ) return 0;
  if(dp[no][id][m]!=-1) return dp[no][id][m];
  int ret=INF;
  for(int i=0;i<(int)R[no].size();i++){
    ret = min(solve(no+1,i,m)+(R[no-1][id].D+R[no][i].D)*ab(R[no-1][id].X-R[no][i].X),ret);
  }
  if(m < M){
    if(no + 1 >= N)
      ret = 0;
    else
      for(int i=0;i<(int)R[no+1].size();i++){
	ret = min(solve(no+2,i,m+1)+(R[no-1][id].D+R[no+1][i].D)*ab(R[no-1][id].X-R[no+1][i].X),ret);
    }
  }
  //  printf("%d %d %d %d  %d\n",no,id,m,ret);
  return dp[no][id][m]=ret;
}
int main(){
  while(1){
    scanf("%d %d",&N,&M);
    if(!N&&!M) break;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<N;i++){
      int k;
      scanf("%d",&k);
      for(int j=0;j<k;j++){
	int x,d;
	scanf("%d %d",&x,&d);
	R[i].push_back(P(x,d));
	///	printf("%d %d\n",R[i][j].X,R[i][j].D);
      }
    }
    int res=INF;
    for(int i=0;i<(int)R[0].size();i++){
      res = min(res,solve(1,i,0));
    }
    if(M>0){
      for(int i=0;i<(int)R[1].size();i++){
	res = min(res,solve(2,i,1));
      }      
    }
    printf("%d\n",res);
    for(int i=0;i<N;i++) R[i].clear();
  }
}