#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;

const int INF = 1<<28;

struct edge_t {
    int from, to, cost;
    edge_t(int from=0, int to=0, int cost=0) : from(from), to(to), cost(cost) {}
    bool operator<(const edge_t &o) const {
        return (cost < o.cost);
    }
    bool operator>(const edge_t &o) const {
        return (cost > o.cost);
    }
};
struct state_t {
    int v;
    int min_cost;
    state_t(int v, int min_cost) : v(v), min_cost(min_cost) {}
    bool operator<(const state_t &o) const {
        return (min_cost < o.min_cost);
    }
    bool operator>(const state_t &o) const {
        return (min_cost > o.min_cost);
    }
};
typedef vector<edge_t> vertex_t;
struct graph_t {
    vector<vertex_t> g;

    graph_t() {}

    graph_t(int vertex_count) {
        g.resize(vertex_count);
        for (int i = 0; i < vertex_count; i++) {
            g[i].resize(1000);
        }
    }
    graph_t(vector<vertex_t> g) : g(g) {}

    inline vertex_t& operator[](int index) {
        return g[index];
    }

    inline void add_edge(int from, int to, double cost) {
        g[from].push_back(edge_t(from, to, cost));
    }
    
    int prim(int hotspots) {
        bool used[g.size()];
        int min_span_cost = 0;
        priority_queue< edge_t, vector<edge_t>, greater<edge_t> > q;

        fill(used, used+g.size(), false);

        for (int i = 0; i < hotspots; i++) {
            used[i] = true;
            for (int j = 0; j < g[0].size(); j++) {
                q.push(g[i][j]);
            }
        }

        while (!q.empty()) {
            edge_t e = q.top(); q.pop();
            if (used[e.to]) continue;
            used[e.to] = true;
            min_span_cost += e.cost;
            for (int i = 0; i < g[e.to].size(); i++) {
                q.push(g[e.to][i]);
            }
        }

        return min_span_cost;
    }
};

int main() {
    int s, d;
    while (cin >> s >> d) {
        if (s == 0 && d == 0) break;
        graph_t graph(1000);
        for (int i = 0; i < s; i++) {
            for (int j = 0; j < d; j++) {
                int distance; cin >> distance;
                if (distance == 0) continue;
                graph[i][s+j] = edge_t(i, s+j, distance);
                graph[s+j][i] = edge_t(i, s+j, distance);
            }
        }
        for (int i = d-1; i >= 0; i--) {
            for (int j = 0; j <= i; j++) {
                if (s+d-i-1 == s+d-i+j-1) continue;
                int distance; cin >> distance;
                if (distance == 0) continue;
                graph[s+d-i-1][s+d-i+j-1] = edge_t(s+d-i-1, s+d-i+j-1, distance);
                graph[s+d-i+j-1][s+d-i-1] = edge_t(s+d-i+j-1, s+d-i-1, distance);
            }
        }

        cout << graph.prim(s) << endl;

//        for (int i = 0; i < s+d; i++) {
//            for (int j = 0; j < s+d; j++) {
//                cout << graph[i][j].cost << ' ';
//            }
//            cout << endl;
//        }
    }
    return 0;
}