// Pyon-Pyon River Crossing

// 動的計画法

#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

typedef pair<int,int> P;
#define X first
#define D second

int main()
{
    int n, m;
    while(cin>>n>>m, n|m) {
        vector<int> k(n);
        int dp[150][11][77] = {0};
        vector< vector<P> > stone(n);
        for(int i=0; i<n; i++) {
            cin>>k[i];
            for(int j=0; j<k[i]; j++) {
                int x, d;
                cin>>x>>d;
                stone[i].push_back(P(x,d));
            }
        }
        for(int i=0; i<n; i++) for(int j=0; j<k[i]; j++) for(int l=0; l<=m; l++) dp[i][j][l] = 1<<30;
        for(int i=0; i<k[0]; i++) dp[0][i][m] = 0;
        for(int i=0; i<k[1]; i++) dp[1][i][m-1] = 0;

        for(int i=0; i<n; i++) {
            for(int j=0; j<k[i]; j++) {
                for(int l=0; l<=m; l++) {

                    if(i+1>=n) continue;
                    for(int jj=0; jj<k[i+1]; jj++) {
                        int add;
                        add = abs((stone[i+1][jj].D+stone[i][j].D)*(stone[i+1][jj].X-stone[i][j].X));
                        dp[i+1][jj][l] = min(dp[i+1][jj][l], dp[i][j][l]+add);
                    }

                    if(i+2>=n) continue;
                    for(int jj=0; jj<k[i+2]; jj++) {
                        int add;
                        add = abs((stone[i+2][jj].D+stone[i][j].D)*(stone[i+2][jj].X-stone[i][j].X));
                        dp[i+2][jj][l-1] = min(dp[i+2][jj][l-1], dp[i][j][l]+add);
                    }
                }
            }
        }

        int ans = 1<<30;
        for(int j=0; j<k[n-1]; j++) {
            for(int l=0; l<=m; l++) {
                ans = min(ans, dp[n-1][j][l]);
            }
        }
        cout<<ans<<endl;
    }
}