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

#include <cstring>

#include <algorithm>

#include <vector>

#include <utility>



using namespace std;



typedef pair<int, int> pii;



#define fst first

#define scd second

#define rep(i,x) for(int i=0;i<(x);++i)



template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}



const int inf = 1e9;



int k[150];

vector<pii> stone[150];

int N, M;



int memo[150][150][10];



int rec(int n, int m, int i)

{

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



	if (~memo[n][m][i]) return memo[n][m][i];



	int res = inf;



	rep(j, k[n + 1]) {

		int dist = (stone[n][i].scd + stone[n + 1][j].scd) * abs(stone[n][i].fst - stone[n + 1][j].fst);

		chmin(res, dist + rec(n + 1, m, j));

	}



	if (m < M) {

		if (n + 2 >= N) return 0;

		rep(j, k[n + 2]) {

			int dist = (stone[n][i].scd + stone[n + 2][j].scd) * abs(stone[n][i].fst - stone[n + 2][j].fst);

			chmin(res, dist + rec(n + 2, m + 1, j));

		}

	}



	return memo[n][m][i] = res;

}



signed main()

{

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

		rep(i, N) {

			scanf("%d", &k[i]);



			stone[i].resize(k[i]);



			rep(j, k[i]) {

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

				stone[i][j].fst = x, stone[i][j].scd = d;

			}

		}



		int ans = inf;



		rep(i, k[0]) {

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

			chmin(ans, rec(0, 0, i));

		}



		if (M > 0) {

			rep(i, k[1]) {

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

				chmin(ans, rec(1, 1, i));

			}

		}



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

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.956355289169616x):
#include <bits/stdc++.h>



using namespace std;



#define int long long



#define rep(i,x) for(int i=0;i<x;++i)

#define all(a) begin(a),end(a)



const int inf = 3e17;



int dp[155][15][100];

int stone[155][15];

int X[155][15];



signed main()

{

    int n, m;

    

    while (cin >> n >> m, n) {

        rep(i, n+5) rep(j, 15) stone[i][j] = inf, X[i][j] = inf;

        rep(i, n+5) rep(j, 15) rep(k, 100) dp[i][j][k] = inf;



        rep(i, n) {

            int k; cin >> k;

            rep(j, k) {

                int x, d; cin >> x >> d;



                X[i][j] = x;



                stone[i][j] = d;

                if (i == 0) dp[0][j][0] = 0;

                if (i == 1) dp[1][j][1] = 0;

            }

        }



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

            for (int j = 0; j < 11; ++j) {

                if (stone[i][j] == inf) continue;



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

                    if (k < m) {

                        rep(l, 11) {

                            if (stone[i + 2][l] == inf) continue;



                            dp[i + 2][l][k + 1] = min(

                                    dp[i + 2][l][k + 1],

                                    dp[i][j][k] + (stone[i][j] + stone[i + 2][l]) * abs(X[i][j] - X[i + 2][l])

                                    );

                        }

                    }



                    rep(l, 11) {

                        if (stone[i + 1][l] == inf) continue;



                        dp[i + 1][l][k] = min(

                                dp[i + 1][l][k],

                                dp[i][j][k] + (stone[i][j] + stone[i + 1][l]) * abs(X[i][j] - X[i + 1][l])

                                );

                    }

                }

            }

        }



        int mi = inf;



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

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

                mi = min(mi, dp[n - 1][i][j]);

            }

        }



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

            for (int j = 0; j <= m - 1; ++j) {

                mi = min(mi, dp[n - 2][i][j]);

            }

        }



        cout << mi << endl;

    }

}