#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <cstdlib>

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i,j,k) for(int i=j;i<(int)(k);++i)
#define foreach(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();++i)
#define all(x) (x).begin(),(x).end()
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
typedef long long ll;
const int INF = 99999999;
const double EPS = 1e-9;

int s,d,in;
vvi S,D;

int main()
{
    while(cin>>s>>d,s&&d){
        S.resize(s,vi(d));
        D.resize(d,vi(d,0));
        rep(i,s)rep(j,d) cin >> S[i][j];
        rep(i,d-1)REP(j,i+1,d){
            cin >> in;
            D[i][j]=D[j][i]=in;
        }
//        rep(i,s)rep(j,d) printf("%2d%s",S[i][j],j!=d-1?" ":"\n");
//        rep(i,d)rep(j,d) printf("%2d%s",D[i][j],j!=d-1?" ":"\n");

        priority_queue<P,vector<P>, greater<P> > pq;
        vi end(d,0);
        P p;
        int ans=0,res=d;

        rep(i,s)rep(j,d)if(S[i][j]!=0) pq.push(P(S[i][j],j));

        while(!pq.empty()){
            p = pq.top(),pq.pop();
            if(end[p.second]) continue;
            end[p.second]=1;
            ans+=p.first;
            if(--res==0) break;

            rep(i,d)if(!end[i]&&D[p.second][i]!=0){
                pq.push(P(D[p.second][i],i));
            }
        }
        cout << ans << endl;
        S.clear(),D.clear();
    }
    return 0;
}