#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }







int main() {
    
    const ll INF = 1e18;
    const int A = 170, B = 15, C = 80;
    int n, m;

    while (cin >> n >> m && n) {
        ll dp[A][B][C]; // 行, その行の石, 何回とばししたか
        vector<pii> v[170];
        
        rep(i, n) {
            int k;
            cin >> k;
            rep(j, k) {
                int col, val;
                cin >> col >> val;
                v[i].eb(col, val);
            }
        }
        
        fill_n(**dp, A * B * C, INF);
        rep(j, 15) dp[0][j][0] = 0;
        rep(j, sz(v[1])) dp[1][j][1] = 0;
        
        rep(i, n - 1) {
            
            rep(k, sz(v[i])) {
                rep(l, m + 1) {
                    rep(j, sz(v[i + 1])) {
                        ll cost = (v[i + 1][j].S + v[i][k].S) * abs(v[i + 1][j].F - v[i][k].F);
                        chmin(dp[i + 1][j][l], dp[i][k][l] + cost);
                        // if (dp[i + 1][j][l] == 5198) cout << v[i + 1][j].F << " " << v[i + 1][j].S << " " << v[i][k].F << " " << v[i][k].S << endl;
                    }
                    if (i <= n - 3 && l <= m - 1) {
                        // if (l == 2) cout << i << " " << k << " " << l << endl;
                        rep(j, sz(v[i + 2])) {
                            
                            ll cost = (v[i + 2][j].S + v[i][k].S) * abs(v[i + 2][j].F - v[i][k].F); // 後ろのi + 1にしてた!!
                            
                            if (dp[i + 2][j][l + 1] > dp[i][k][l] + cost) {
                                chmin(dp[i + 2][j][l + 1], dp[i][k][l] + cost);
                                // if (dp[i + 2][k][l + 1] == 27027) cout << i + 2 << " " << k << " " << l + 1 << " " << dp[i][k][l] << " " << cost << " " << endl;
                            }
                            
                        }
                    }
                }
            }
        }
        
        ll ans = INF;
        rep(j, B) rep(k, m + 1) chmin(ans, dp[n - 1][j][k]);
        
        rep(j, B) rep(k, m) chmin(ans, dp[n - 2][j][k]); // これ忘れてた
        
        
        cout << ans << '\n';
        
        
        // cout << dp[2][0][1] << endl;

        /*
        rep(i, n) {
            cout << endl << "i " << i << endl;
            rep(j, B) {
                cout << "j " << j << endl;
                rep(k, m + 1) cout << dp[i][j][k] << " "; cout << endl;
            }
        }*/
         
    }
    
}



Measured memory_bytes: 4644