#include <bits/stdc++.h>
using namespace std;
int n, m;
int mida;
vector<map<int, long long int> > g;
int ini, fin;
long long int tope;
long long int aumentaflux() {
  vector<int> anterior(mida, -1);
  vector<long long int> flujo(mida, 0);
  priority_queue<pair<long long int, int> > q;
  q.push(pair<long long int, long long int>(tope, ini));
  anterior[ini] = ini;
  flujo[ini] = tope;
  while (not q.empty()) {
    pair<long long int, int> p = q.top();
    q.pop();
    int u = p.second;
    long long int fu = p.first;
    if (fu == flujo[u]) {
      if (u == fin) {
        while (u != ini) {
          g[anterior[u]][u] -= fu;
          g[u][anterior[u]] += fu;
          u = anterior[u];
        }
        return fu;
      }
      map<int, long long int> &ar = g[u];
      for (map<int, long long int>::iterator it = ar.begin(); it != ar.end();
           it++) {
        int v = it->first;
        long long int fv = it->second;
        long long int nextf = min(fu, fv);
        if (nextf > flujo[v]) {
          q.push(pair<long long int, int>(nextf, v));
          flujo[v] = nextf;
          anterior[v] = u;
        }
      }
    }
  }
  return 0;
}
long long int maxflow() {
  long long int f = 0;
  long long int a = aumentaflux();
  while (a > 0) {
    f += a;
    a = aumentaflux();
  }
  return f;
}
int main() {
  cin >> n >> m;
  mida = n * m + 2;
  ini = n * m;
  fin = n * m + 1;
  g = vector<map<int, long long int> >(mida);
  for (int j = 0; j < m - 1; j++) {
    for (int i = 0; i < n; i++) {
      long long int value;
      cin >> value;
      int u = i * m + j;
      int v = i * m + j + 1;
      g[u][v] = value;
      g[v][u] = value;
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      long long int value;
      cin >> value;
      int u = i * m + j;
      int v = ((i + 1) % n) * m + j;
      g[u][v] = value;
      g[v][u] = value;
    }
  }
  tope = 5000000000LL;
  for (int i = 0; i < n; i++) {
    int uini = i * m;
    int ufin = i * m + m - 1;
    g[uini][ini] = 0;
    g[ini][uini] = tope;
    g[ufin][fin] = tope;
    g[fin][ufin] = 0;
  }
  cout << maxflow() << endl;
}
