#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j;
  int s, d;
  while (cin >> s >> d && s + d) {
    priority_queue<pair<int, pair<int, int> >,
                   vector<pair<int, pair<int, int> > >,
                   greater<pair<int, pair<int, int> > > >
        a;
    for (i = 0; i < s; i++) {
      for (j = 0; j < d; j++) {
        int p;
        cin >> p;
        if (p) a.push(make_pair(p, make_pair(i, s + j)));
      }
    }
    for (i = 0; i < d - 1; i++) {
      for (j = i + 1; j < d; j++) {
        int p;
        cin >> p;
        if (p) a.push(make_pair(p, make_pair(s + i, s + j)));
      }
    }
    int b[100];
    for (i = 0; i < s + d; i++) b[i] = i;
    int sm = 0;
    while (a.empty() == 0) {
      int x, y, z;
      z = a.top().first;
      x = a.top().second.first;
      y = a.top().second.second;
      a.pop();
      int t = 0, u = 0;
      if (x >= s) {
        for (i = 0; i < s; i++) {
          if (b[i] == b[x]) break;
        }
        if (i == s) t = 1;
      }
      if (y >= s) {
        for (i = 0; i < s; i++) {
          if (b[i] == b[y]) break;
        }
        if (i == s) u = 1;
      }
      if (t || u) {
        for (i = 0; i < s + d; i++) {
          if (i != y && b[i] == b[y]) b[i] = b[x];
        }
        b[y] = b[x];
        sm += z;
      }
    }
    cout << sm << endl;
  }
  return 0;
}
