#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int gor[100100][5];
int ver[100100][5];
long long ans[100100][32];
bool prov[32][32][5];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m - 1; i++)
    for (int j = 0; j < n; j++) scanf("%d", &gor[i][j]);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) scanf("%d", &ver[i][j]);
  for (int i = 0; i < 100100; i++)
    for (int j = 0; j < 32; j++) ans[i][j] = (1ll << 62);
  ans[0][0] = 0;
  for (int i = 0; i < 32; i++)
    for (int j = 0; j < 32; j++)
      for (int k = 0; k < 5; k++)
        if ((((i & (1 << k)) == 0) ^ ((j & (1 << k)) == 0)) == 1)
          prov[i][j][k] = true;
  for (int i = 0; i < 1; i++)
    for (int j = 0; j < n; j++)
      if ((((i & (1 << j)) == 0) ^ ((i & (1 << ((j + 1) % n))) == 0)) == 1)
        ans[0][i] += 1ll * ver[0][j];
  for (int i = 1; i < m; i++)
    for (int j = 0; j < (1 << n); j++) {
      long long help = 0, help1 = 0;
      for (int z = 0; z < n; z++)
        if ((((j & (1 << z)) == 0) ^ ((j & (1 << ((z + 1) % n))) == 0)) == 1)
          help += 1ll * ver[i][z];
      for (int z = 0; z < (1 << n); z++) {
        for (int k = 0; k < n; k++)
          if (prov[j][z][k]) help1 += gor[i - 1][k];
        if (ans[i][j] > ans[i - 1][z] + help + help1)
          ans[i][j] = ans[i - 1][z] + help + help1;
        help1 = 0;
      }
    }
  cout << ans[m - 1][(1 << n) - 1];
  return 0;
}
