#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
static const int MAX = 51;
static const int INFTY = 101;
class edge {
public:
    int source, target, cost;
    edge(int source, int target = 0, int cost = 0) : source(source), target(target), cost(cost) {}
};
int V;

class DisjointSet {
public:
    vector<int> rank, p;
    DisjointSet() {}
    DisjointSet(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        for (int i = 0; i < size; i++) makeSet(i);
    }

    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }

    bool same (int x, int y) {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y) {
        if (rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
    }

    int findSet(int x) {
        if (x != p[x]) {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

bool compare(const edge& a, const edge& b) {
    return a.cost < b.cost;
}

int main(){

    int s, d, cost, ans;
    for (; ;) {
        scanf("%d %d", &s, &d);
        if (s == 0 && d == 0) break;
        V = s + d;
        vector<edge> G;
        for (int i = 0; i < s; i++) {
            for (int j = s; j < V; j++) {
                std::scanf("%d", &cost);
                cost = (cost == 0) ? INFTY : cost;
                if (cost != 0) G.push_back(edge(0, j, cost));
            }
        }

        for (int i = s; i < V-1; i++) {
            for (int j = i+1; j < V; j++) {
                std::scanf("%d", &cost);
                cost = (cost == 0) ? INFTY : cost;
                if (cost != 0) G.push_back(edge(i, j, cost));
            }
        }

        std::sort(G.begin(), G.end(), compare);
        DisjointSet ds(V+1);
        ans = 0;
        int p;
        for (int i = 0; i < G.size(); i++) {
            if (!ds.same(G[i].source, G[i].target)) {
                ds.unite(G[i].source, G[i].target);
                ans+= G[i].cost;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

