#include <bits/stdc++.h>
using namespace std;
const long long INF64 = (long long)1e18;
const int MAXN = 5;
const int MAXM = 100000;
int n, m;
int horiz[MAXN][MAXM];
int vert[MAXN + 1][MAXM];
long long dp[1 << MAXN], nxt[1 << MAXN];
bool CheckBit(int mask, int bit);
long long stupid() {
  for (int i = 0; i < (1 << n); ++i) dp[i] = nxt[i] = INF64;
  dp[0] = 0;
  for (int col = 1; col < m; ++col) {
    for (int mask = 0; mask < (1 << n); ++mask) {
      if (dp[mask] == INF64) continue;
      for (int new_mask = 0; new_mask < (1 << n); ++new_mask) {
        long long add = dp[mask];
        for (int i = 0; i < n; ++i) {
          if (!CheckBit(mask, i) && CheckBit(new_mask, i)) {
            add += horiz[i][col - 1];
          }
          if (CheckBit(mask, i) && !CheckBit(new_mask, i)) {
            add += horiz[i][col - 1];
          }
          int ni = (i + 1);
          if (ni == n) ni = 0;
          if (!CheckBit(new_mask, i) && CheckBit(new_mask, ni)) {
            add += vert[i][col];
          }
          if (CheckBit(new_mask, i) && !CheckBit(new_mask, ni)) {
            add += vert[i][col];
          }
        }
        nxt[new_mask] = min(nxt[new_mask], add);
      }
    }
    for (int mask = 0; mask < (1 << n); ++mask) {
      dp[mask] = nxt[mask];
      nxt[mask] = INF64;
    }
  }
  return dp[(1 << n) - 1];
}
long long f[1 << MAXN], f2[1 << MAXN];
long long smart() {
  for (int i = 0; i < 1 << n; ++i) {
    f[i] = f2[i] = INF64;
  }
  f[0] = 0;
  for (int col = 1; col < m; ++col) {
    for (int row = 0; row < n; ++row) {
      for (int mask = 0; mask < 1 << n; ++mask) {
        long long add = f[mask];
        if (CheckBit(mask, row)) {
          add += horiz[row][col - 1];
        }
        if (row && CheckBit(mask, row - 1)) {
          add += vert[row - 1][col];
        }
        if (row == n - 1 && CheckBit(mask, 0)) {
          add += vert[n - 1][col];
        }
        int new_mask = ((mask | (1 << row)) ^ (1 << row));
        f2[new_mask] = min(f2[new_mask], add);
        add = f[mask];
        if (!CheckBit(mask, row)) {
          add += horiz[row][col - 1];
        }
        if (row && !CheckBit(mask, row - 1)) {
          add += vert[row - 1][col];
        }
        if (row == n - 1 && !CheckBit(mask, 0)) {
          add += vert[n - 1][col];
        }
        new_mask = (mask | (1 << row));
        f2[new_mask] = min(f2[new_mask], add);
      }
      for (int mask = 0; mask < 1 << n; ++mask) {
        f[mask] = f2[mask];
        f2[mask] = INF64;
      }
    }
  }
  return f[(1 << n) - 1];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int col = 0; col < m - 1; ++col) {
    for (int row = 0; row < n; ++row) {
      scanf("%d", &horiz[row][col]);
    }
  }
  for (int col = 0; col < m; ++col) {
    for (int row = 0; row < n; ++row) {
      scanf("%d", &vert[row][col]);
    }
  }
  cout << smart() << endl;
  return 0;
}
bool CheckBit(int mask, int bit) { return (mask & (1 << bit)); }
