#include <bits/stdc++.h>
long a[100006][8] = {0};
long b[100006][8] = {0};
long long s[100006][38] = {0};
long long s2[100006][38] = {0};
long long f[100006][38] = {0};
int main() {
  long n, m, i, j, k, l;
  scanf("%ld%ld", &n, &m);
  for (i = 2; i <= m; i++) {
    for (j = 1; j <= n; j++) scanf("%ld", &a[i][j]);
    for (k = 0; k < (1 << n); k++)
      for (j = 1; j <= n; j++)
        if ((1 << (j - 1)) & k) s[i][k] += a[i][j];
  }
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) scanf("%ld", &b[i][j]);
    for (k = 0; k < (1 << n); k++)
      for (j = 1; j <= n; j++)
        s2[i][k] +=
            b[i][j] * ((!!(1 << (j - 1) & k)) ^ (!!((1 << (j % n)) & k)));
  }
  f[1][0] = 0;
  for (i = 1; i < (1 << n); i++) f[1][i] = 200000000000000000LL;
  for (i = 2; i <= m; i++) {
    for (j = 0; j < (1 << n); j++) f[i][j] = 200000000000000000LL;
    for (j = 0; j < (1 << n); j++)
      for (k = 0; k < (1 << n); k++)
        if (f[i - 1][j] + s[i][j ^ k] + s2[i][k] < f[i][k])
          f[i][k] = f[i - 1][j] + s[i][j ^ k] + s2[i][k];
  }
  printf("%I64d\n", f[m][(1 << n) - 1]);
  return 0;
}
