// Slower C++ solution:
#include<iostream>

#include<climits>

#include<string>

#include<stack>

#include<vector>

#include<map>

#include<queue>

#include<algorithm>

#include<cmath>

using namespace std;

#define fr first

#define sc second

#define INF INT_MAX

typedef pair<int,int> Pi;

typedef pair< Pi,pair<Pi,int> > P;

struct Edge{

  int to,denger;

  Edge(){}

  Edge(int to,int denger):to(to),denger(denger){};

};

int n,m;

int m_cost[151][11][(151+1)/2+1];

vector<vector<Edge> > info;

int Dijkstra();

int main(){

  while(cin >> n >> m && n||m){

    info.resize(n);

    for(int i=0,k;i<n;i++){

      cin >> k;

      for(int j=0,t,d;j<k;j++){

        cin >> t >> d;

        info[i].push_back(Edge(t,d));

      }

    }

    cout << Dijkstra() << endl;

    info.clear();

  }

}

int Dijkstra(){

  for(int i=0;i<151;i++){

    for(int j=0;j<11;j++){

      for(int k=0;k<(151+1)/2+1;k++){

        m_cost[i][j][k] = INF;

      }

    }

  }

  priority_queue<P,vector<P>,greater<P> > que;

  for(int i=0,l=info[0].size();i<l;i++){

    que.push(P(Pi(0,m),make_pair(Pi(0,info[0][i].to),info[0][i].denger)));

    m_cost[0][i][m] = 0;

  }

  if(m != 0){

    for(int i=0,l=info[1].size();i<l;i++){

      que.push(P(Pi(0,m-1),make_pair(Pi(1,info[1][i].to),info[1][i].denger)));

      m_cost[1][i][m-1] = 0;

    }

  }

  while(!que.empty()){

    P p = que.top();

    int den = p.fr.fr,limit = p.fr.sc,slip=p.sc.sc;

    Pi pt = Pi(p.sc.fr.fr,p.sc.fr.sc);

    que.pop();

    if(pt.fr + 1 >= n) return den;

    for(int j=1;j<3;j++){

      if(j==2 && limit == 0) break;

      if(j==2 && pt.fr + 1 == n) break;

      if(j==2 && pt.fr + 2 == n) return den;

      if(j==1 && pt.fr + 1 == n) return den;

      for(int i=0,l=info[pt.fr+j].size();i<l;i++){

        int next_now = info[pt.fr+j][i].to;

        int next_den = info[pt.fr+j][i].denger;

        int hmhm = den + (slip + next_den) * abs(next_now - pt.sc);

        if(hmhm < m_cost[pt.fr+j][i][limit-(j-1)]){

          m_cost[pt.fr+j][i][limit-(j-1)] = hmhm;

          que.push(P(Pi(hmhm,limit-(j-1)),make_pair(Pi(pt.fr+j,next_now),next_den)));

        }

      }

    }

  }

}

// Faster C++ solution for the same problem (measured speedup: 1.5580827954402214x):
#include<bits/stdc++.h>

using namespace std;

const int INF = 1 << 30 ;

struct edge{

  int pos, strong ;

  int dp[77];



  edge(int pos, int strong): pos(pos), strong(strong){

    fill_n( dp, 77, INF);

  };

  edge(){};

};



int main(){

  int n; //行数 

  int m; //ジャンプの数



  vector< edge > node[152] ;



  while(cin >> n >> m, n){

    for(int i = 0; i < n; i++){

      int k;

      cin >> k ;

      node[i].resize(k) ;

      for(int j = 0; j < k; j++){

        int x, d;

        cin >> x >> d ;

        node[i][j] = edge( x, d);

      }

    }



    for(int i = 0; i < node[0].size(); i++){ //最初は普通にジャンプ

      node[0][i].dp[0] = 0;

    }

    for(int i = 0; i < node[1].size(); i++){ //最初はジャンプする

      node[1][i].dp[1] = 0 ;

    }

    for(int i = 0; i < n; i++){

      for(int j = 0; j < node[i].size(); j++){

        for(int k = 0; k <= m; k++){

          if(node[i][j].dp[k] != INF){

            if(k != m){

              for(int l = 0; l < node[i + 2].size(); l++){

                node[i + 2][l].dp[k + 1] = min( node[i + 2][l].dp[k + 1], node[i][j].dp[k] + (node[i + 2][l].strong + node[i][j].strong) * abs(node[i + 2][l].pos - node[i][j].pos));

              }

            }

            for(int l = 0; l < node[i + 1].size(); l++){

              node[i + 1][l].dp[k] = min( node[i + 1][l].dp[k], node[i][j].dp[k] + (node[i + 1][l].strong + node[i][j].strong) * abs(node[i + 1][l].pos - node[i][j].pos));

            }

          }

        }

      }

    }

    int ret = INF ;

    for(int i = 0; i < node[n - 1].size(); i++){

      for(int j = 0; j <= m; j++){

        ret = min( ret, node[n - 1][i].dp[j]);

      }

    }

    for(int i = 0; i < node[n - 2].size(); i++){

      for(int j = 0; j < m; j++){

        ret = min( ret, node[n - 2][i].dp[j]);

      }

    }

    cout << ret << endl ;

  }

}