#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int R,C;
    Scd2(R,C);

    int N = R*C;

    vector<vii> e(N*2);

    int a;
    Rep(i,N){
        if( i%C == C-1 ) continue;
        Scd(a);
        e[i].push_back({i+1, a});
        e[i+1].push_back({i, a});
    }
    Rep(i,N-C){
        Scd(a);
        e[i].push_back({i+C, a});
        e[i+C+N].push_back({i+N, 1});
    }
    Rep(i,N){
        e[i].push_back({i+N, 1});
        e[i+N].push_back({i, 0});
    }

    vi d(N*2, INF);
    priority_queue<pii, vii, greater<pii>> q;
    q.push({0,0});
    d[0] = 0;

    while(q.size()){
        pii top = q.top();
        q.pop();
        int from = top.second;
        int dist = top.first;
        if( d[from] < dist ) continue;
        for( pii tow : e[from] ) {
            int to = tow.first;
            int cost = tow.second;
            if( dist + cost < d[to] ) {
                d[to] = dist + cost;
                q.push({d[to], to});
            }
        }
    }

    printf ("%d\n", d[N-1]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
  int R,C,inf=1001001001;
  cin >> R >> C;
  vector<vector<int>> A(R,vector<int>(C-1)), B(R-1,vector<int>(C));
  for(int i=0;i<R;i++){
    for(int j=0;j<C-1;j++){
      cin >> A[i][j];
    }
  }
  for(int i=0;i<R-1;i++){
    for(int j=0;j<C;j++){
      cin >> B[i][j];
    }
  }
  
  vector<vector<int>> V(R,vector<int>(C,inf));
  V[0][0] = 0;
  priority_queue<pair<int,int>> Q;
  Q.push(make_pair(0,0));
  while(!Q.empty()){
    pair<int,int> p = Q.top();
    Q.pop();
    int r = p.second % R, c = p.second / R;
    if(V[r][c]!=-p.first) continue;
    
    if(c+1<C){
      if(V[r][c+1]>V[r][c]+A[r][c]){
        V[r][c+1] = V[r][c] + A[r][c];
        Q.push(make_pair(-V[r][c+1],(c+1)*R+r));
      }
    }
    if(c-1>=0){
      if(V[r][c-1]>V[r][c]+A[r][c-1]){
        V[r][c-1] = V[r][c] + A[r][c-1];
        Q.push(make_pair(-V[r][c-1],(c-1)*R+r));
      }
    }
    if(r+1<R){
      if(V[r+1][c]>V[r][c]+B[r][c]){
        V[r+1][c] = V[r][c] + B[r][c];
        Q.push(make_pair(-V[r+1][c],c*R+r+1));
      }
    }
    for(int i=1;r-i>=0;i++){
      if(V[r-i][c]>V[r][c]+i+1){
        V[r-i][c] = V[r][c] + i+1;
        Q.push(make_pair(-V[r-i][c],c*R+r-i));
      }
    }
  }
  
  cout << V[R-1][C-1] << endl;
  return 0;
}
