#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;

int f(int b,int r,int c){
  return b*500*500+r*500+c;
}

int main(){
  int R,C; cin >> R >> C;
  vvi g(500*500*2);
  vvi co(500*500*2);
  rep(r,R) rep(c,C-1){
    int in; cin >> in;
    g[f(0,r,c)].pb(f(0,r,c+1));
    g[f(0,r,c+1)].pb(f(0,r,c));
    co[f(0,r,c)].pb(in);
    co[f(0,r,c+1)].pb(in);
  }
  rep(r,R-1) rep(c,C){
    int in; cin >> in;
    g[f(0,r,c)].pb(f(0,r+1,c));
    co[f(0,r,c)].pb(in);
  }
  rep(r,R-1) rep(c,C){
    g[f(1,r+1,c)].pb(f(1,r,c));
    co[f(1,r+1,c)].pb(1);
  }
  rep(r,R) rep(c,C){
    g[f(0,r,c)].pb(f(1,r,c));
    co[f(0,r,c)].pb(1);
    g[f(1,r,c)].pb(f(0,r,c));
    co[f(1,r,c)].pb(0);
  }
  vector<int> D(500*500*2, -1);
  vector<bool> used(500*500*2, false);
  priority_queue<pair<int,int>,
                 vector<pair<int,int>>,
                 greater<pair<int,int>>> q;
  q.push({(int)0,f(0,0,0)});
  while(!q.empty()){
    int d = q.top().first; int to = q.top().second; q.pop();
    if(used[to]) continue;
    used[to] = true; D[to] = d;
    rep(i,sz(g[to])){
      int nxt=g[to][i];
      if(D[nxt] != -1 && D[nxt] <= D[to] + co[to][i]) continue;
      q.push({D[to] + co[to][i], nxt});
    }
  }

  int ans = D[f(0,R-1,C-1)];
  cout << ans << endl;
  return 0;
}

#include <queue>
#include <cstdio>
#include <cstring>
#pragma GCC optimize(2)
#define int long long
const int N = 505;
struct twt {
    int x, y, d;
    bool operator < (twt b) const {
        return d > b.d;
    }
};
std::priority_queue<twt> que;
int R, C, a[N][N], b[N][N], dis[N][N];
void Dijkstra() {
    memset(dis, 0x3f, sizeof dis);
    que.push((twt){1, 1, 0});
    dis[1][1] = 0;
    while(!que.empty()) {
        register twt now = que.top(); que.pop();
        register int x = now.x, y = now.y, d = now.d;
      	if(x == R && y == C) return ;
        if(now.d != dis[x][y]) continue;
        if(y < C && d + a[x][y] < dis[x][y+1]) {
            dis[x][y+1] = d + a[x][y];
            que.push((twt){x, y+1, dis[x][y+1]});
        }
        if(y > 1 && d + a[x][y-1] < dis[x][y-1]) {
            dis[x][y-1] = d + a[x][y-1];
            que.push((twt){x, y-1, dis[x][y-1]});
        }
        if(x < R && d + b[x][y] < dis[x+1][y]) {
            dis[x+1][y] = d + b[x][y];
            que.push((twt){x+1, y, dis[x+1][y]});
        }
        for(register int i = 1; i < x; i++) {
            if(d + i+1 < dis[x-i][y]) {
                dis[x-i][y] = d+i+1;
                que.push((twt){x-i, y, dis[x-i][y]});
            }
        }
    }
}
signed main() {
    scanf("%lld%lld", &R, &C);
    for(register int i = 1; i <= R; i++)
        for(register int j = 1; j < C; j++) scanf("%lld", &a[i][j]);
    for(register int i = 1; i < R; i++)
        for(register int j = 1; j <= C; j++) scanf("%lld", &b[i][j]);
    Dijkstra();
    printf("%lld", dis[R][C]);
    return 0;
}