#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
//const ll MOD = 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

const int MAX_V = 200010;

int par[MAX_V];
int rank_[MAX_V];

void init(int n) {

    for (int i = 0; i < n; ++i) {
        par[i] = i;
        rank_[i] = 0;
    }
}

int root(int x) {
    return par[x] == x ? x : par[x] = root(par[x]); //経路圧縮
}

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

void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (rank_[x] < rank_[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rank_[x] == rank_[y]) rank_[x]++;
    }
}

struct edge {
    ll u, v, cost;
};

vector<edge> E;

bool comp(edge &e1, edge &e2) {
    return e1.cost < e2.cost;
}

ll kruskal(int n) {
    sort(E.begin(), E.end(), comp);
    init(n);
    ll res = 0;
    for (auto e : E) {
        if (!same(e.u, e.v)) {
            unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);

    int s, d;
    int dist;
    while (1) {
        cin >> s >> d;
        if (s == 0 && d == 0) break;
        E.clear();

        rep(i, s) rep(j, d) {
            cin >> dist;
            if (dist == 0) continue;
            E.push_back({i, s + j, dist});
        }

        rep(i, d) REP(j, i + 1, d) {
            cin >> dist;
            if (dist == 0) continue;
            E.push_back({s + i, s + j, dist});
        }

        rep(i, s) REP(j, i + 1, s) {
            E.push_back({i, j, 0});
        }

        cout << kruskal(s + d) << endl;

    }

    return 0;
}


