#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005;
long long A[MaxN][(1 << (5))], B[MaxN][(1 << (5))], dp[MaxN][(1 << (5))];
const long long Inf = 1LL << 60;
int main() {
  int N, M;
  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))) A[i][k] += x;
    }
  for (int i = 0; i < M; 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))) == 0) ^ ((k & (1 << ((j + 1) % N))) == 0))
          B[i][k] += x;
    }
  for (int i = 0; i <= M; i++)
    for (int j = 0; j < (1 << (N)); j++) dp[i][j] = Inf;
  dp[0][0] = 0;
  for (int i = 1; i < M; i++)
    for (int j = 0; j < (1 << (N)); j++) {
      dp[i][j] = min(dp[i][j], A[i - 1][j] + B[i][j]);
      for (int k = j; k > 0; k -= k & (-k))
        dp[i][j] = min(dp[i][j], dp[i - 1][k] + A[i - 1][k ^ j] + B[i][j]);
    }
  printf("%I64d\n", dp[M - 1][(1 << (N)) - 1]);
  return 0;
}
