#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
 
const int INF = 1<<29;
 
int dp[256][16][128];
vector<P> stones[256];
 
int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
 
  while (true) {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0) break;
   
    REP(i, N) {
      stones[i].clear();
      int k;
      cin >> k;
      REP(j, k) {
    int x, d;
    cin >> x >> d;
    stones[i].push_back(P(x, d));
      }
    }
 
    REP(i, N) REP(j, stones[i].size()) REP(k, M+1) dp[i][j][k] = INF;
    REP(j, stones[0].size()) dp[0][j][0] = 0;
    REP(j, stones[1].size()) dp[1][j][1] = 0;
    REP(i, N-1) {
      REP(j, stones[i+1].size()) {
    int x_now = stones[i+1][j].first, d_now = stones[i+1][j].second;
    REP(k, stones[i].size()) {
      int x_prev = stones[i][k].first, d_prev = stones[i][k].second;
      int safe = (d_now + d_prev) * abs(x_now - x_prev);
      REP(m, M+1) {
        dp[i+1][j][m] = min(dp[i+1][j][m], dp[i][k][m] + safe);
      }
    }
    if (i > 0) {
      REP(k, stones[i-1].size()) {
        int x_prev = stones[i-1][k].first, d_prev = stones[i-1][k].second;
        int safe = (d_now + d_prev) * abs(x_now - x_prev);
        REP(m, M) {
          dp[i+1][j][m+1] = min(dp[i+1][j][m+1], dp[i-1][k][m] + safe);
        }
      }
    }
      }
    }
 
    int ans = INF;
    REP(j, stones[N-1].size()) REP(m, M+1) ans = min(ans, dp[N-1][j][m]);
    REP(j, stones[N-2].size()) REP(m, M) ans = min(ans, dp[N-2][j][m]);
    cout << ans << endl;
  }
  return 0;
}