#include <bits/stdc++.h>
using namespace std;
const int _ = (1 << 5) + 7;
const int __ = 1e5 + 7;
int n, m, tot;
int num[_][10];
long long f[_][__], g[_][__], c[7][__][2], ans;
void Init() {
  cin >> n >> m, tot = (1 << n) - 1;
  for (int j = 1; j < m; ++j)
    for (int i = 1; i <= n; ++i) scanf("%lld", &c[i][j][1]);
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i) {
      scanf("%lld", &c[i][j][0]);
      c[i][j][0] += c[i][j - 1][0];
    }
    c[0][j][0] = c[n][j][0] - c[n][j - 1][0] + c[0][j - 1][0];
  }
  for (int i = 0; i <= tot; ++i) {
    for (int k = 1; k <= n; ++k) num[i][k] = ((i >> (k - 1)) & 1);
    num[i][0] = num[i][n];
    num[i][n + 1] = num[i][1];
  }
}
void print(int x) {
  for (int i = 0; i < n; ++i) {
    printf("%d", x & 1);
    x >>= 1;
  }
}
void Run() {
  memset(f, 0x3f, sizeof f);
  memset(g, 0x3f, sizeof g);
  ans = f[0][0];
  for (int j = 1; j < m; ++j) {
    for (int i = 0; i <= tot; ++i) {
      long long w = 0, w1 = 0;
      for (int k = 1; k <= n; ++k)
        if (num[i][k]) {
          w += c[k][j][1];
          if (!num[i][k - 1]) w1 += c[k - 1][j][0];
          if (!num[i][k + 1]) w1 += c[k][j][0];
        }
      f[i][j] = min(f[i][j], w);
      g[i][j] = min(g[i][j], min(g[i][j - 1], w - w1));
      for (int s = 0; s <= tot; ++s) {
        if (s & i) continue;
        long long w = g[i][j], w1 = 0;
        bool flag = 1;
        for (int k = 1; k <= n; ++k) {
          if (!num[s][k]) continue;
          w += c[k][j + 1][1];
          if (!(num[i][k - 1] | num[s][k - 1]) and
              !(num[i][k + 1] | num[s][k + 1])) {
            if (j == 3 and i == 24 and s == 7) cerr << k << endl;
            flag = 0;
            break;
          }
          if (num[i][k - 1])
            w += c[k - 1][j + 1][0];
          else if (!num[s][k - 1])
            w1 += c[k - 1][j + 1][0];
          if (num[i][k + 1])
            w += c[k][j + 1][0];
          else if (!num[s][k + 1])
            w1 += c[k][j + 1][0];
        }
        if (!flag) continue;
        f[i | s][j + 1] = min(f[i | s][j + 1], w);
        g[i | s][j + 1] = min(g[i | s][j + 1], w - w1);
      }
    }
    ans = min(ans, f[tot][j]);
  }
  cout << ans << endl;
}
int main() {
  Init();
  Run();
  return 0;
}
