#include <bits/stdc++.h>
using namespace std;
namespace l {
long long const I = 1000000000000LL;
class ll {
 public:
  int l1;
  int *li, *lI, *il, *i1;
  struct ii {
    long long iI, Il;
    int I1, Ii, II;
    ii() {
      iI = Il = 0;
      I1 = Ii = II = -1;
    }
    ii(long long iI, long long Il, int I1, int Ii, int II = -1)
        : iI(iI), Il(Il), I1(I1), Ii(Ii), II(II) {}
  };
  vector<ii>* lll;

 private:
  int ll1(int lli, int llI, int l1l) {
    if (l1l == llI) return 0;
    for (int l11 = 0; l11 < lli; l11++) {
      li[l11] = 0;
      lI[l11] = -1;
      il[l11] = -1;
    }
    li[llI] = 1;
    int l1i = 0, l1I = 1;
    i1[l1i] = llI;
    while (l1i < l1I) {
      int lil = i1[l1i++];
      for (int l11 = 0; l11 < (int)lll[lil].size(); l11++)
        if (!li[lll[lil][l11].I1])
          if (lll[lil][l11].iI > lll[lil][l11].Il) {
            li[lll[lil][l11].I1] = 1;
            lI[lll[lil][l11].I1] = lil;
            il[lll[lil][l11].I1] = l11;
            i1[l1I] = lll[lil][l11].I1;
            l1I++;
          }
    }
    return li[l1l];
  }
  long long li1(int lli, int llI, int l1l) {
    int l11 = l1l;
    long long lii = I;
    while (l11 != llI) {
      int liI = lI[l11];
      lii = min(lii, lll[liI][il[l11]].iI - lll[liI][il[l11]].Il);
      l11 = liI;
    }
    l11 = l1l;
    while (l11 != llI) {
      int liI = lI[l11];
      int lIl = il[l11];
      lll[liI][lIl].Il += lii;
      lll[l11][lll[liI][lIl].Ii].Il -= lii;
      l11 = liI;
    }
    return lii;
  }

 public:
  void clear() {
    if (lll)
      for (int l11 = 0; l11 < l1; l11++) lll[l11].clear();
  }
  ll(int lI1) {
    l1 = lI1;
    li = new int[l1];
    lI = new int[l1];
    il = new int[l1];
    i1 = new int[l1];
    lll = new vector<ii>[l1];
  }
  ~ll() {
    delete[] lll;
    delete[] i1;
    delete[] il;
    delete[] lI;
    delete[] li;
  }
  void lIi(int lII, int ill, long long iI, long long il1 = 0, int II = -1) {
    if (lII == ill) return;
    lll[lII].push_back(ii(iI, 0, ill, (int)lll[ill].size(), II));
    lll[ill].push_back(ii(il1, 0, lII, ((int)lll[lII].size()) - 1, II));
  }
  long long ili(int lli, int llI, int l1l) {
    if (lli <= 0 || lli > l1 || llI < 0 || llI >= lli || l1l < 0 || l1l >= lli)
      return -1;
    long long ilI = 0;
    while (ll1(lli, llI, l1l)) ilI += li1(lli, llI, l1l);
    return ilI;
  }
};
class i1l {
 public:
  int l1;
  int *li, *lI, *il, *i1;
  struct ii {
    long long iI, Il;
    int I1, Ii, II;
    ii() {
      iI = Il = 0;
      I1 = Ii = II = -1;
    }
    ii(long long iI, long long Il, int I1, int Ii, int II = -1)
        : iI(iI), Il(Il), I1(I1), Ii(Ii), II(II) {}
  };
  vector<ii>* lll;

 private:
  int ll1(int lli, int llI, int l1l, long long i11) {
    if (l1l == llI) return 0;
    for (int l11 = 0; l11 < lli; l11++) {
      li[l11] = 0;
      lI[l11] = -1;
      il[l11] = -1;
    }
    li[llI] = 1;
    int l1i = 0, l1I = 1;
    i1[l1i] = llI;
    while (l1i < l1I) {
      int lil = i1[l1i++];
      for (int l11 = 0; l11 < (int)lll[lil].size(); l11++)
        if (!li[lll[lil][l11].I1])
          if (lll[lil][l11].iI >= lll[lil][l11].Il + i11) {
            li[lll[lil][l11].I1] = 1;
            lI[lll[lil][l11].I1] = lil;
            il[lll[lil][l11].I1] = l11;
            i1[l1I] = lll[lil][l11].I1;
            l1I++;
          }
    }
    return li[l1l];
  }
  long long li1(int lli, int llI, int l1l) {
    int l11 = l1l;
    long long lii = I;
    while (l11 != llI) {
      int liI = lI[l11];
      lii = min(lii, lll[liI][il[l11]].iI - lll[liI][il[l11]].Il);
      l11 = liI;
    }
    l11 = l1l;
    while (l11 != llI) {
      int liI = lI[l11];
      int lIl = il[l11];
      lll[liI][lIl].Il += lii;
      lll[l11][lll[liI][lIl].Ii].Il -= lii;
      l11 = liI;
    }
    return lii;
  }

 public:
  void clear() {
    if (lll)
      for (int l11 = 0; l11 < l1; l11++) lll[l11].clear();
  }
  i1l(int lI1) {
    l1 = lI1;
    li = new int[l1];
    lI = new int[l1];
    il = new int[l1];
    i1 = new int[l1];
    lll = new vector<ii>[l1];
  }
  ~i1l() {
    delete[] lll;
    delete[] i1;
    delete[] il;
    delete[] lI;
    delete[] li;
  }
  void lIi(int lII, int ill, long long iI, long long il1 = 0, int II = -1) {
    if (lII == ill) return;
    lll[lII].push_back(ii(iI, 0, ill, (int)lll[ill].size(), II));
    lll[ill].push_back(ii(il1, 0, lII, ((int)lll[lII].size()) - 1, II));
  }
  long long ili(int lli, int llI, int l1l) {
    if (lli <= 0 || lli > l1 || llI < 0 || llI >= lli || l1l < 0 || l1l >= lli)
      return -1;
    long long i1i = 0;
    for (int l11 = 0; l11 < lli; l11++)
      for (int liI = 0; liI < (int)lll[l11].size(); liI++)
        i1i = max(i1i, lll[l11][liI].iI);
    if (i1i <= 0) return 0;
    long long i11 = 1;
    while (i11 <= i1i) i11 *= 2;
    i11 /= 2;
    long long ilI = 0;
    while (i11 >= 1) {
      while (ll1(lli, llI, l1l, i11)) ilI += li1(lli, llI, l1l);
      i11 /= 2;
    }
    return ilI;
  }
};
class i1I {
 public:
  int l1;
  int iil;
  long long* ii1;
  int* i1;
  struct ii {
    long long iii;
    long long iiI;
    int I1, II;
    ii *iIl, *iI1;
    ii() {
      iii = iiI = 0;
      I1 = II = -1;
      iIl = iI1 = NULL;
    }
  };
  typedef ii* iIi;
  ii* iII;
  iIi *Ill, *Il1;
  iIi Ili;

 private:
  inline int IlI(long long& lII, const long long ill) {
    if (ill < lII) {
      lII = ill;
      return 1;
    }
    return 0;
  }
  int I1l(int lli, int llI, int l1l, long long i11) {
    if (l1l == llI) return 0;
    fill(ii1, ii1 + lli, I);
    ii1[l1l] = 0;
    int l1i = 0, l1I = 1;
    i1[l1i] = l1l;
    while (l1i < l1I) {
      int lil = i1[l1i++];
      for (iIi l11 = Ill[lil]; l11; l11 = l11->iIl)
        if (l11->iI1->iiI >= i11 && IlI(ii1[l11->I1], ii1[lil] + 1)) {
          i1[l1I] = l11->I1;
          l1I++;
          if (l11->I1 == llI) return 1;
        }
    }
    return 0;
  }
  long long li1(int lli, int llI, int l1l, int I11, long long i11,
                long long I1i) {
    if (I11 == l1l) return I1i;
    long long ilI = 0;
    long long I1I = 0;
    for (iIi& l11 = Il1[I11]; l11; l11 = l11->iIl) {
      if (l11->iiI >= i11 && ii1[I11] == ii1[l11->I1] + 1)
        if ((I1I = li1(lli, llI, l1l, l11->I1, i11, min(I1i, l11->iiI))) > 0)
          l11->iiI -= I1I, l11->iI1->iiI += I1I, I1i -= I1I, ilI += I1I;
      if (!I1i) break;
    }
    return ilI;
  }

 public:
  void clear() {
    Ili = iII;
    for (int l11 = 0; l11 < l1; l11++) Ill[l11] = NULL, Il1[l11] = NULL;
  }
  i1I(int lI1, int Iil) {
    l1 = lI1;
    iil = Iil;
    ii1 = new long long[lI1];
    i1 = new int[lI1];
    iII = new ii[Iil * 2 + 10];
    Ill = new iIi[lI1];
    Il1 = new iIi[lI1];
    clear();
  }
  ~i1I() {
    delete[] Il1;
    delete[] Ill;
    delete[] iII;
    delete[] i1;
    delete[] ii1;
  }
  void lIi(int lII, int ill, long long iI, long long il1 = 0, int II = -1) {
    if (lII == ill) return;
    Ili->I1 = ill;
    Ili->iii = iI;
    Ili->iiI = iI;
    Ili->iIl = Ill[lII];
    Ili->II = II;
    Ill[lII] = Ili++;
    Ili->I1 = lII;
    Ili->iii = il1;
    Ili->iiI = il1;
    Ili->iIl = Ill[ill];
    Ili->II = II;
    Ill[ill] = Ili++;
    Ill[lII]->iI1 = Ill[ill];
    Ill[ill]->iI1 = Ill[lII];
  }
  long long ili(int lli, int llI, int l1l) {
    if (lli <= 0 || lli > l1 || llI < 0 || llI >= lli || l1l < 0 || l1l >= lli)
      return -1;
    long long i1i = 0;
    for (int l11 = 0; l11 < lli; l11++)
      for (iIi liI = Ill[l11]; liI; liI = liI->iIl) i1i = max(i1i, liI->iii);
    if (i1i <= 0) return 0;
    long long i11 = 1;
    while (i11 <= i1i) i11 *= 2;
    i11 /= 2;
    long long ilI = 0;
    while (i11 >= 1) {
      while (I1l(lli, llI, l1l, i11)) {
        memcpy(Il1, Ill, lli * sizeof(iIi));
        ilI += li1(lli, llI, l1l, llI, i11, I);
      }
      i11 /= 2;
    }
    return ilI;
  }
};
}  // namespace l
using namespace l;
i1I* Ii1;
int main() {
  int lli, Iii;
  scanf("%d%d", &lli, &Iii);
  Ii1 = new i1I(lli * Iii + 2,
                lli * (Iii - 1) + Iii * (lli - 1) + Iii + 10 + lli * 2);
  for (int liI = 0; liI < Iii - 1; liI++)
    for (int l11 = 0; l11 < lli; l11++) {
      int IiI;
      scanf("%d", &IiI);
      Ii1->lIi((l11 * Iii + liI), (l11 * Iii + (liI + 1)), IiI, IiI);
    }
  for (int liI = 0; liI < Iii; liI++) {
    for (int l11 = 0; l11 < lli - 1; l11++) {
      int IiI;
      scanf("%d", &IiI);
      Ii1->lIi((l11 * Iii + liI), ((l11 + 1) * Iii + liI), IiI, IiI);
    }
    int IiI;
    scanf("%d", &IiI);
    Ii1->lIi(liI, (lli - 1) * Iii + liI, IiI, IiI);
  }
  for (int l11 = 0; l11 < lli; l11++)
    Ii1->lIi(lli * Iii, (l11 * Iii), I / 10, I / 10);
  for (int l11 = 0; l11 < lli; l11++)
    Ii1->lIi(lli * Iii + 1, (l11 * Iii + (Iii - 1)), I / 10, I / 10);
  cout << (Ii1->ili(lli * Iii + 2, lli * Iii, lli * Iii + 1));
  delete Ii1;
  return 0;
}
