// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <vector>

#include <string>

#include <map>

#include <set>

#include <queue>

#include <stack>

#include <algorithm>



using namespace std;



#define rep(i,j) REP((i), 0, (j))

#define REP(i,j,k) for(int i=(j);(i)<(k);++i)

#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))

#define ALL(v) (v).begin(), (v).end()

#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))

#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)

#define SQ(x) ((x)*(x))

#define Mod(x, mod) (((x)+(mod)%(mod))

#define MP make_pair

#define PB push_back

#define F first

#define S second

#define INF 1LL << 60

#define EPS 1e-10

#define MOD 1000000007



typedef pair<int, int> P;

typedef vector<int> vi;

typedef queue<int> qi;

typedef long long ll;



vector<P>St[256];

int N, M;

ll dp[256][16][128];



ll dfs(int n, int x, int m){

  if(n>=N-1) return 0;

  if(n>=N-2 && m) return 0;

  ll &res = dp[n][x][m];

  if(res >= 0) return res;

  res = INF;

  int pos = St[n][x].first ,slip = St[n][x].second;

  rep(i, St[n+1].size()){

      P tar = St[n+1][i];

      res = min(res, dfs(n+1, i, m)+(ll)(slip+tar.second)*(ll)(abs(pos-tar.first)));

  }

  if(m && n < N-2){

    rep(i, St[n+2].size()){

      P tar = St[n+2][i];

      res = min(res, dfs(n+2, i, m-1)+(ll)(slip+tar.second)*(ll)(abs(pos-tar.first)));

    }

  }

  //  cout << n << " " << x << " "<< m <<" " << res << endl;

  return res;

}



int main(){

  while(scanf("%d%d", &N, &M) && N){

    int k, x, d;

    memset(dp, -1, sizeof(dp));

    rep(i,N) St[i].clear();

    rep(i, N){

      scanf("%d", &k);

      rep(j,k){

	scanf("%d%d", &x, &d);

	St[i].push_back(P(x, d));

      }

    }

    

    ll res = INF;

    rep(i, St[0].size()) res = min(res, dfs(0, i, M));

    if(M) rep(i, St[1].size()) res = min(res, dfs(1, i, M-1));



    printf("%lld\n", res);

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.135907499749024x):
#include <cstdio>

#include <cstring>

#include <vector>

#include <algorithm>



using namespace std;



typedef pair<int, int>P;

const int INF = 1<<29;

int N,M;

int dp[256][128][16];

vector<P> s[151];



int main(){

  while(scanf("%d%d", &N,&M) && N||M){

    for(int i=0;i<151;i++) s[i].clear();

    for(int i=0;i<151;i++) for(int j=0;j<76;j++) for(int k=0;k<11;k++) dp[i][j][k] = INF;

    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);

	s[i].push_back(P(x,d));

      }

    }

    

    for(int i=0;i<s[0].size();i++) dp[0][M][i] = min(dp[0][M][i], 0);

    if(M) for(int i=0;i<s[1].size();i++) dp[1][M-1][i] = min(dp[1][M-1][i], 0);

    /*    for(int m=0;m<=M;m++){

      for(int i=0;i<N;i++){

	for(int j=0;j<s[i].size();j++) printf("%d ", dp[i][m][j]);

	puts("");

      }puts("");

      } */   



    for(int i=0;i<N-1;i++){

      for(int j=0;j<s[i].size();j++){

	for(int m=0;m<=M;m++){

	  if(dp[i][m][j] == INF) continue;

	  for(int k=0;k<s[i+1].size();k++){

	    dp[i+1][m][k] = min(dp[i+1][m][k],

				dp[i][m][j]+(s[i+1][k].second+s[i][j].second)*abs(s[i+1][k].first-s[i][j].first));

	  }

	  if(i+2 < N && m) for(int k=0;k<s[i+2].size();k++){

	      dp[i+2][m-1][k] = min(dp[i+2][m-1][k],

				    dp[i][m][j]+(s[i+2][k].second+s[i][j].second)*abs(s[i+2][k].first-s[i][j].first));

	    }

	}

      }

      //      printf("%d\n" ,i);

      /*      for(int m=0;m<=M;m++){

	for(int i=0;i<N;i++){

	  for(int j=0;j<s[i].size();j++) printf("%d ", dp[i][m][j]);

	  puts("");

	}puts("");

      }*/

    }

    /*    for(int m=0;m<=M;m++){

      for(int i=0;i<N;i++){

	for(int j=0;j<s[i].size();j++) printf("%d ", dp[i][m][j]);

	puts("");

      }puts("");

      }*/

    

    int res = INF;

    for(int i=0;i<s[N-1].size();i++) for(int m=0;m<=M;m++) res = min(res, dp[N-1][m][i]);

    for(int i=0;i<s[N-2].size();i++) for(int m=1;m<=M;m++) res = min(res, dp[N-2][m][i]);

    printf("%d\n", res);

  }

  return 0;

}