// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

ll dp[200][200][15];
int solve_testcase() {
    int N, M; scanf("%d%d", &N, &M);
    if(N == 0 and M == 0) return 1;

    vector< vector< pair<ll, ll> > > info(N+2);
    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);
            info[i].emplace_back(x, d);
        }
    }

    fill(dp[0][0], dp[N+2][0], LONGINF);
    dp[0][0][0] = 0;
    for(int i=0; i<=N; i++) {
        for(int j=0; j<=M; j++) {
            for(int k=0; k<10; k++) {
                if(dp[i][j][k] == LONGINF) continue;
                if(i + 1 <= N + 1) {
                    if(i == 0 or i + 1 == N + 1) {
                        chmin(dp[i+1][j][0], dp[i][j][k]);
                        for(int l=0; l<(int)info[i].size(); l++) {
                            chmin(dp[i+1][j][l], dp[i][j][k]);
                        }
                    }
                    else if(k < info[i-1].size() and info[i].size()) {
                        for(int l=0; l<(int)info[i].size(); l++) {
                            int d = info[i-1][k].second + info[i][l].second;
                            int x = abs(info[i-1][k].first - info[i][l].first);
                            chmin(dp[i+1][j][l], dp[i][j][k] + d*x);
                        }
                    }
                }
                if(i + 2 <= N + 1 and j + 1 <= M) {
                    if(i == 0 or i + 2 == N + 1) {
                        chmin(dp[i+2][j+1][0], dp[i][j][k]);
                        for(int l=0; l<(int)info[i+1].size(); l++) {
                            chmin(dp[i+2][j+1][l], dp[i][j][k]);
                        }
                    }
                    else if(k < info[i-1].size() and info[i+1].size()) {
                        for(int l=0; l<(int)info[i+1].size(); l++) {
                            int d = info[i-1][k].second + info[i+1][l].second;
                            int x = abs(info[i-1][k].first - info[i+1][l].first);
                            chmin(dp[i+2][j+1][l], dp[i][j][k] + d*x);
                        }
                    }
                }
            }
        }
    }

    ll ans = LONGINF;
    for(int i=0; i<=M; i++) for(int j=0; j<10; j++) chmin(ans, dp[N+1][i][j]);
    printf("%lld\n", ans);
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 6788