#include <bits/stdc++.h>
using namespace std;
long long pd[5][100100][33], ch[6][100100], cv[6][100100], n, m;
long long calc(int a, int b, int mb) {
  if (b == m) return 0;
  if (a == n) {
    long long cl = (mb % 2 != (mb >> (n - 1))) ? cv[a - 1][b] : 0;
    return cl + calc(0, b + 1, mb);
  }
  if (pd[a][b][mb] != -1) return pd[a][b][mb];
  long long res = 0x3f3f3f3f3f3f3f3fLL;
  for (long long i = 0; i < (long long)2; i++) {
    if (!i && b == m - 1) continue;
    long long ce = (i != (mb >> (n - 1))) ? ch[a][b - 1] : 0;
    long long cc = (a > 0 && i != mb % 2) ? cv[a - 1][b] : 0;
    res = min(res, calc(a + 1, b, (mb * 2 + i) & ((1 << n) - 1)) + ce + cc);
  }
  return (pd[a][b][mb] = res);
}
int main() {
  scanf("%d%d", &n, &m);
  for (long long i = 0; i < (long long)m - 1; i++)
    for (long long j = 0; j < (long long)n; j++) scanf("%d", &ch[j][i]);
  for (long long i = 0; i < (long long)m; i++)
    for (long long j = 0; j < (long long)n; j++) scanf("%d", &cv[j][i]);
  memset(pd, -1, sizeof(pd));
  printf("%lld\n", calc(0, 1, 0));
  return 0;
}
