#include <iostream>
#include <queue>
#define INF 1000000000
using namespace std;
int n,m;
int mp[202][202];


int prim() {
  int flg[202] = {}; 
  int dis[202] = {};
  int sum = 0;

  for(int i=0;i<=n+m;i++) dis[i] = INF;
  dis[0] = 0;

  while(1) {
    
    int mindis = INF,nx,cnt=0;
    for(int j=0;j<n+m;j++)
      if (flg[j] == 1)cnt++;
      else if(dis[j] < mindis) mindis = dis[j] , nx = j;
    if(cnt == n+m) break;

    flg[nx] = 1;
    sum += mindis;

    for(int j=0;j<n+m;j++) 
      if(mp[nx][j] < dis[j]) dis[j] = mp[nx][j];
  }
  return sum;
  
}


int main() {

  while(1) {
  cin >> n >> m;
  if(n == 0 && m == 0) break;

  for(int i=0;i<=n+m;i++)
    for(int j=0;j<=n+m;j++)
      if(i<n && j < n)mp[i][j] = 0;
      else  mp[i][j] = INF;
 
  for(int i=0;i<n;i++) 
    for(int j=0;j<m;j++){
      int a;
      cin >> a;
      if(a == 0) continue;
      mp[i][n+j] = a;
      mp[n+j][i] = a;
    }

  for(int i=0;i<m-1;i++) 
    for(int j=i+1;j<m;j++) {
      int a;
      cin >> a;
      if(a ==0) continue;
      mp[n+i][n+j] = a;
      mp[n+j][n+i] = a;
    }
  
  cout << prim()<<endl;
  
  }
  return 0;
}