#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 50;
const double EPS = 1E-10;
int par[200];
int ran[200];
void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    ran[i] = 0;
  }
}
int find(int x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = find(par[x]);
}
bool same(int x, int y) { return find(x) == find(y); }
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (ran[x] < ran[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (ran[x] == ran[y]) ran[x]++;
  }
}
int main() {
  int s, d;
  int cost;
  while (cin >> s >> d && (s || d)) {
    init(s + d);
    priority_queue<pair<int, pair<int, int> >,
                   vector<pair<int, pair<int, int> > >,
                   greater<pair<int, pair<int, int> > > >
        que;
    for (int i = 0; i < s; i++) {
      for (int j = 0; j < d; j++) {
        cin >> cost;
        if (cost) {
          que.push(pair<int, pair<int, int> >(cost, pair<int, int>(j, d + i)));
        }
      }
    }
    for (int i = 0; i < d - 1; i++) {
      for (int j = 0; j < d - i - 1; j++) {
        cin >> cost;
        if (cost) {
          que.push(
              pair<int, pair<int, int> >(cost, pair<int, int>(j, j + i + 1)));
        }
      }
    }
    bool ok = false;
    int res = 0;
    while (!que.empty() && !ok) {
      pair<int, pair<int, int> > pp = que.top();
      que.pop();
      cost = pp.first;
      int a = pp.second.first;
      int b = pp.second.second;
      bool f = true;
      if (a >= d || b >= d) {
        if (a >= d) swap(a, b);
        for (int i = 0; i < s; i++) {
          if (same(a, i + d)) f = false;
        }
      }
      if (a < d && b < d) {
        bool fa = false;
        bool fb = false;
        for (int i = 0; i < s; i++) {
          if (same(a, i + d)) fa = true;
          if (same(b, i + d)) fb = true;
        }
        if (fa && fb) f = false;
      }
      if (!same(a, b) && f) {
        res += cost;
        unite(a, b);
      }
      ok = true;
      for (int i = 0; i < d; i++) {
        bool f = false;
        for (int j = 0; j < s; j++) {
          if (same(i, j + d)) f = true;
        }
        if (!f) ok = false;
      }
    }
    cout << res << endl;
  }
  return 0;
}
