#include <iostream>
#include <vector>
#include <climits>
#include <cmath>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


long dist(pair<int, int> s1, pair<int, int> s2) {
  return abs(s1.first - s2.first) * (s1.second + s2.second);
}

int main(void) {
  while(1) {
    long N, M;
    vector< pair<long, long> > S[150];
    vector<long> dp[150][150];

    cin >> N >> M;
    if(N == 0 && M == 0) break;
    REP(i, 0, N) {
      int k;
      cin >> k;
      REP(j, 0, k) {
        long x, d;
        cin >> x >> d;
        S[i].push_back(pair<long, long>(x, d));
      }
    }

    long ans = INT_MAX;
    REP(i, 0, N) {
      REP(j, 0, M + 1) {
        REP(k, 0, S[i].size()) {
          long m = INT_MAX;
          if(i >= 1) {
            REP(l, 0, S[i - 1].size()) {
              m = min(m, dp[i - 1][j][l] + dist(S[i][k], S[i - 1][l]));
            }
          }
          if(i >= 2 && j >= 1) {
            REP(l, 0, S[i - 2].size()) {
              m = min(m, dp[i - 2][j - 1][l] + dist(S[i][k], S[i - 2][l]));
            }
          }
          if(i == 0 && j == 0) m = 0;
          if(i == 0 && j >= 1) m = INT_MAX;
          if(i == 1 && j == 1) m = 0;
          dp[i][j].push_back(m);

          if(((i == N - 2 && j < M) || (i == N - 1))) {
            ans = min(ans, m);
          }
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}