#include <iostream>
#include <algorithm>
#include <queue>
#define MAX 101
#define INF 1000000
using namespace std;

int s, d;
int G[MAX][MAX];

typedef pair<int, int> P;

int solve() {
  int cost[MAX];
  priority_queue< P, vector<P>, greater<P> > PQ;
  int ans = 0;
  bool visited[MAX];

  fill(cost, cost+d+1, INF);
  fill(visited, visited+d+1, false);
  cost[0] = 0;
  PQ.push(P(0, 0));

  while(!PQ.empty()) {
    P p = PQ.top(); PQ.pop();
    int v = p.second;
    if(visited[v]) continue;
    visited[v] = true;
    for(int i = 0; i < d+1; i++) {
      if(v == i) continue;
      if(visited[i]) continue;
      if(cost[i] > G[v][i]) {
	cost[i] = G[v][i];
	PQ.push(P(cost[i], i));
      }
    }
  }
  for(int i = 0; i < d+1; i++) {
    ans += cost[i];
    //cout << cost[i] << endl;
  }
  return ans;
}

int main() {
  while(( cin >> s >> d ) && s && d) {
    fill(G[0], G[MAX], INF);
    for(int i = 0; i < s; i++) {
      for(int j = 0; j < d; j++) {
	int a;
	cin >> a;
	if(a == 0) a = INF;
	if(i == 0) G[d][j] = G[j][d] = a;
	else       G[d][j] = G[j][d] = min(G[d][j], a);
      }
    }

    for(int i = 0; i < d; i++) {
      for(int j = i+1; j < d; j++) {
	int a;
	cin >> a;
	if(a == 0) a = INF;
	G[i][j] = G[j][i] = a;
      }
    }

    cout << solve() << endl;
  }
}