#include <bits/stdc++.h>
using namespace std;
template <class t>
ostream &operator<<(ostream &tout, const vector<t> &s) {
  tout << '[';
  for (int i = 0; i < s.size(); i++)
    if (i + 1 == s.size())
      tout << s[i];
    else
      tout << s[i] << ',';
  tout << ']';
  return (tout);
}
const int MAX_N = 100000 + 200;
const long long INF = 1ll << 50;
int n, m;
vector<int> mai;
vector<vector<int> > all;
long long A[300][32], B[300][32];
int eA[MAX_N][5], eB[MAX_N][5];
long long smA[MAX_N][32], smB[MAX_N][32];
void bt(int s, int t) {
  t = 1;
  if (s > n) {
    all.push_back(mai);
    return;
  }
  for (int i = 0; i <= t; i++) {
    mai.push_back(i);
    bt(s + 1, max(i + 1, t));
    mai.pop_back();
  }
}
void relax(vector<int> &s) {
  for (int i = 0; i < s.size(); i++)
    if (s[i]) s[i] += 100;
  int count = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] >= 100) {
      if (count == 0) count++;
      int temp = s[i];
      for (int j = 0; j < s.size(); j++)
        if (s[j] == temp) s[j] = count;
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d %d", &n, &m);
  bt(1, 1);
  for (int i = 0; i < all.size(); i++)
    for (int j = 0; j < (1 << n); j++) {
      int temp = j;
      vector<int> sam(n);
      for (int k = 0; k < sam.size(); k++) sam[k] = k + 100;
      for (int k = 0; k < n; k++, temp /= 2)
        if (temp % 2) sam[k] = all[i][k];
      relax(sam);
      A[i][j] = lower_bound(all.begin(), all.end(), sam) - all.begin();
    }
  for (int i = 0; i < all.size(); i++)
    for (int j = 0; j < (1 << n); j++) {
      vector<int> sam = all[i];
      for (int count = 0; count < n; count++) {
        int temp = j;
        for (int k = 0; k < n; k++, temp /= 2)
          if (temp % 2) {
            sam[k] = min(sam[k], sam[(k + 1) % n]);
            sam[(k + 1) % n] = min(sam[(k + 1) % n], sam[k]);
          }
      }
      relax(sam);
      B[i][j] = lower_bound(all.begin(), all.end(), sam) - all.begin();
    }
  for (int i = 2; i <= m; i++)
    for (int j = 0; j < n; j++) {
      scanf("%d", &eA[i][j]);
    }
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < n; j++) {
      scanf("%d", &eB[i][j]);
    }
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < (1 << n); j++) {
      int temp = j;
      for (int k = 0; k < n; k++, temp /= 2)
        if (temp % 2 == 0) {
          smA[i][j] += eA[i][k];
          smB[i][j] += eB[i][k];
        }
    }
  vector<long long> dyna(all.size(), INF);
  dyna[0] = 0;
  for (int count = m; count >= 1; count--) {
    vector<long long> res(dyna.size(), INF);
    for (int i = 0; i < all.size(); i++)
      for (int j = 0; j < (1 << n); j++) {
        long long sum = smB[count][j];
        res[B[i][j]] = min(res[B[i][j]], dyna[i] + sum);
      }
    dyna = res;
    if (count > 1) {
      vector<long long> res(dyna.size(), INF);
      for (int i = 0; i < all.size(); i++)
        for (int j = 0; j < (1 << n); j++) {
          long long sum = smA[count][j];
          res[A[i][j]] = min(res[A[i][j]], dyna[i] + sum);
        }
      dyna = res;
    }
  }
  long long ans = INF;
  for (int i = 0; i < all.size(); i++)
    if (*min_element(all[i].begin(), all[i].end()) != 0)
      ans = min(ans, dyna[i]);
  cout << ans << endl;
}
