#include <iostream>
#include <algorithm>

using namespace std;

const int inf = 99999;

int prim(int a[101][101], int n)
{
	int r = 0, cost[101], t;
	bool vis[101];
	
	fill(vis, vis+101, true);
	fill(cost, cost+101, inf);
	cost[0] = 0;
	
	while(1){
		t = -1;
		
		for(int i = 0; i < n; i++){
			if(vis[i] && (t == -1 || cost[i] < cost[t])){
				t = i;
			}
		}
		
		if(t == -1){
			break;
		}
		vis[t] = false;
		r += cost[t];
		
		for(int i = 0; i < n; i++){
			cost[i] = min(cost[i], a[t][i]);
		}
	}
	
	return r;
}

int main()
{
	int s, d, t, a[101][101];
	
	while(cin>>s>>d && s && d){
		fill(&a[0][0], &a[100][100], inf);
		for(int i = s; i < 101; i++){
			a[i][i] = 0;
		}
		for(int i = 0; i < s; i++){
			for(int j = 0; j < s; j++){
				a[i][j] = 0;
			}
		}
		
		for(int i = 0; i < s; i++){
			for(int j = 0; j < d; j++){
				cin >> t;
				if(t == 0){
					t = inf;
				}
				a[i][s+j] = a[s+j][i] = t;
			}
		}
		
		for(int i = 0; i < d; i++){
			for(int j = i+1; j < d; j++){
				cin >> t;
				if(t == 0){
					t = inf;
				}
				a[s+i][s+j] = a[s+j][s+i] = t;
			}
		}
		
		cout << prim(a, s+d) << endl;
	}
	
	return 0;
}