#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

long long minSpanningTree(const vector<vector<Edge> >& edges)
{
    int n = edges.size();
    vector<bool> used(n, false);
    int usedNum = 0;
    vector<int> minCost(n, INT_MAX);
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, 0));

    long long ret = 0;
    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(used[v])
            continue;
        ret += p.first;
        used[v] = true;
        if(++usedNum == n)
            return ret;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(!used[e.to] && e.cost < minCost[e.to]){
                minCost[e.to] = e.cost;
                q.push(make_pair(e.cost, e.to));
            }
        }
    }
    return -1;
}

int main()
{
    for(;;){
        int s, d;
        cin >> s >> d;
        if(s == 0)
            return 0;

        vector<vector<Edge> > edges(s+d);
        for(int i=1; i<s; ++i){
            edges[0].push_back(Edge(i, 0));
            edges[i].push_back(Edge(0, 0));
        }

        for(int i=0; i<s; ++i){
            for(int j=s; j<s+d; ++j){
                int a;
                cin >> a;
                if(a > 0){
                    edges[i].push_back(Edge(j, a));
                    edges[j].push_back(Edge(i, a));
                }
            }
        }

        for(int i=s; i<s+d-1; ++i){
            for(int j=i+1; j<s+d; ++j){
                int a;
                cin >> a;
                if(a > 0){
                    edges[i].push_back(Edge(j, a));
                    edges[j].push_back(Edge(i, a));
                }
            }
        }

        cout << minSpanningTree(edges) << endl;
    }
}