#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;
	char c;
	char str[1024];
	string s;
	ll l;
	int nextInt(){
		scanf("%d", &n);
		return n;
	}
	ll nextLong(){
		scanf("%lld", &l);
		return l;
	}
	char nextChar(){
		scanf("%c", &c);
		return c;
	}
	string next(){
		scanf("%s", str);
		return string(str);
	}
	string nextLine(){
		getline(cin, s);
		return s;
	}
};
Input in;

struct edge
{
	int to, cost;
	edge(){};
	edge(int to, int cost) : to(to), cost(cost){};
};

int dist[200][200][200];
vector<vi> x(200);
vector<vi> d(200);

int main(){
	while(1){
		int n = in.nextInt(), m = in.nextInt();
		if(n == 0 && m == 0) break;
		x.clear(); d.clear();
		x.resize(n); d.resize(n);
		rep(i, n){
			int k = in.nextInt();
			rep(j, k){
				int tx = in.nextInt(), td = in.nextInt();
				x[i].pb(tx);
				d[i].pb(td);
			}
		}
		vector<edge> g[200][200], g2[200][200];
		rep(i, n-1){
			rep(j, x[i].size()){
				rep(k, x[i+1].size()){
					int c = (d[i][j] + d[i+1][k]) * abs(x[i][j]- x[i+1][k]);
					g[i][j].pb({k, c});
				}
				if( i + 2 < n);
				else continue;
				rep(k, x[i+2].size()){
					int c = (d[i][j] + d[i+2][k]) * abs(x[i][j]- x[i+2][k]);
					g2[i][j].pb({k, c});
				}
			}
		}
		rep(i, 200) rep(j, 200) rep(k, 200) dist[i][j][k] = i == 0 ? 0 : INF;
		auto dijkstra = [&]{
			priority_queue<pair<pii, pii>, vector<pair<pii, pii> >, greater<pair<pii, pii> > > q;
			for(int i = 0; i < x[0].size(); i++) q.push(mp(mp(0, 0), mp(0, i)));
			for(int i = 0; i < x[1].size(); i++) q.push(mp(mp(0, 1), mp(1, i)));
			pair<pii, pii> p;
			while(!q.empty()){
				p = q.top();	q.pop();
				int cost = p.fi.fi, jump = p.fi.se, from1 = p.se.fi, from2 = p.se.se;
				for(int i = 0; i < g[from1][from2].size(); i++){
					int to1 = from1 + 1, to2 =g[from1][from2][i].to, c = g[from1][from2][i].cost;
					if(dist[to1][to2][jump] <= cost + c) continue;
					dist[to1][to2][jump] = cost + c;
					q.push(mp(mp(cost + c, jump), mp(to1, to2)));
				}
				if(jump > m) continue;
				for(int i = 0; i < g2[from1][from2].size(); i++){
					int to1 = from1 + 2, to2 =g2[from1][from2][i].to, c = g2[from1][from2][i].cost;
					if(dist[to1][to2][jump + 1] <= cost + c) continue;
					dist[to1][to2][jump + 1] = cost + c;
					q.push(mp(mp(cost + c, jump + 1), mp(to1, to2)));
				}	
			}
		};
		dijkstra();
		int ans = INF;
		for(int i = 0; i  < x[n-1].size(); i++){
			for(int j = 0; j <= m; j++) ans = min(ans, dist[n-1][i][j]);
		}
		for(int i = 0; i  < x[n-2].size(); i++){
			for(int j = 0; j < m; j++) ans = min(ans, dist[n-2][i][j]);
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 38668