#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const long long inf = 1000000000000000000LL;
int n, m;
long long ver[maxn][32];
long long hor[maxn][32];
long long f[maxn][32];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < (m - 1); ++i)
    for (int j = 0; j < (n); ++j) {
      int x;
      scanf("%d", &x);
      for (int k = 0; k < ((1 << n)); ++k)
        if (k & (1 << j)) ver[i + 1][k] += x;
    }
  for (int i = 0; i < (m); ++i)
    for (int j = 0; j < (n); ++j) {
      int x;
      scanf("%d", &x);
      if (j < n - 1) {
        for (int k = 0; k < ((1 << n)); ++k)
          if (((k & (1 << j)) != 0) != ((k & (1 << (j + 1))) != 0)) {
            hor[i][k] += x;
          }
      } else {
        for (int k = 0; k < ((1 << n)); ++k)
          if (((k & (1 << j)) != 0) != ((k & 1) != 0)) {
            hor[i][k] += x;
          }
      }
    }
  for (int i = 0; i < (m + 1); ++i)
    for (int j = 0; j < ((1 << n)); ++j) f[i][j] = inf;
  f[1][(1 << n) - 1] = 0;
  for (int i = 1; i < m; ++i)
    for (int j = 0; j < ((1 << n)); ++j)
      if (f[i][j] != inf)
        for (int k = 0; k < ((1 << n)); ++k)
          if ((j & k) == k)
            f[i + 1][k] = min(f[i + 1][k], f[i][j] + ver[i][j ^ k] + hor[i][k]);
  cout << f[m][0] << endl;
  return 0;
}
