#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

class NODE{
public:
	int to,cost;
	NODE(int a,int b){to = a , cost = b;}
};
bool operator<(const NODE &a,const NODE &b){
	return a.cost > b.cost;
}
int main(){
	int s,d;
	while(cin >> s >> d , s || d){
		vector<NODE> graph[100];
		rep(i,s)rep(j,s)if(i!=j)graph[i].push_back(NODE(j,0));
		int ret = 0;
		rep(i,s){
			rep(j,d){
				int c; cin >> c;
				if(c){
					graph[i].push_back(NODE(s+j,c));
					graph[s+j].push_back(NODE(i,c));
				}
			}
		}
		rep(i,d-1){
			rep(j,d-1-i){
				int c; cin >> c;
				if(c){
					graph[s+i].push_back(NODE(s+1+i+j,c));
					graph[s+1+i+j].push_back(NODE(s+i,c));
				}
			}
		}
		vector<int> get;
		priority_queue<NODE> Q;
		Q.push(NODE(0,0));
		bool done[100] = {0};
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if(done[q.to])continue;
			else ret += q.cost , done[q.to] = true;
			get.push_back(q.cost);
			rep(i,graph[q.to].size()) Q.push(graph[q.to][i]);
		}
		cout << ret << endl;
	}
}