import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

struct P {
    int x, d;
}

void main() {
    int n, m;
    while (scanf("%d %d\n", &n, &m), n || m) {
        P[][] g = new P[][n];
        foreach (i; 0 .. n) {
            int k; scanf("%d", &k);
            foreach (j; 0 .. k) {
                int x, d; scanf(" %d %d", &x, &d);
                g[i] ~= P(x, d);
            }
        }
        int cache[150][10][100]; memset(cast(void*)cache, -1, cache.sizeof);
        int dfs(int y, int i, int m) {
            if (y == n) return 0;
            if (y == n - 1) return 0;
            if (cache[y][i][m] >= 0) return cache[y][i][m];
            int r = int.max;
            P c = g[y][i];
            if (m >= 1) {
                if (y + 2 == n) {
                    return 0;
                } else {
                    foreach (int j, s; g[y + 2]) {
                        r = min(r, abs(s.x - c.x) * (s.d + c.d) + dfs(y + 2, j, m - 1));
                    }
                }
            }
            foreach (int j, s; g[y + 1]) {
                r = min(r, abs(s.x - c.x) * (s.d + c.d) + dfs(y + 1, j, m));
            }
            return cache[y][i][m] = r;
        }
        int ans = int.max;
        if (m >= 1) {
            foreach (int i, _; g[1]) {
                ans = min(ans, dfs(1, i, m - 1));
            }
        }
        foreach (int i, _; g[0]) {
            ans = min(ans, dfs(0, i, m));
        }
        ans.writeln;
    }
}