#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int N = 5, M = int(1e5) + 100;
int n, m;
int vertical[M][N], horizontal[M][N];
long long dp[2][1 << N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < m; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", vertical[i] + j);
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", horizontal[i] + j);
    }
  }
  int now = 1, old = 0;
  for (int msk = 0; msk < 1 << n; msk++) {
    dp[now][msk] = INF;
  }
  dp[now][0] = 0;
  for (int r = 0; r < m; r++) {
    for (int c = 0; c < n; c++) {
      swap(now, old);
      for (int msk = 0; msk < 1 << n; msk++) {
        dp[now][msk] = INF;
      }
      for (int msk = 0; msk < 1 << n; msk++) {
        long long cost = dp[old][msk];
        if (cost == INF) {
          continue;
        }
        if (r == 1 && c == 0 && msk) {
          continue;
        }
        for (int choose = 0; choose < 2; choose++) {
          long long new_cost = cost;
          if (r > 0) {
            new_cost += (msk >> c & 1 ^ choose) * vertical[r][c];
          }
          if (c > 0) {
            new_cost += (msk >> c - 1 & 1 ^ choose) * horizontal[r][c - 1];
          }
          if (c == n - 1) {
            new_cost += (msk & 1 ^ choose) * horizontal[r][n - 1];
          }
          int new_msk = msk ^ msk & 1 << c | choose << c;
          if (new_cost < dp[now][new_msk]) {
            dp[now][new_msk] = new_cost;
          }
        }
      }
    }
  }
  cout << dp[now][(1 << n) - 1] << endl;
}
