#include<bits/stdc++.h>
//#include<atcoder/all>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace atcoder;
//using namespace boost::multiprecision;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef unsigned long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll mod=998244353;
const ll LINF=1ll<<60;
const int INF=1<<30;
int dx[]={0,1,0,-1,0,1,-1,1,-1};
int dy[]={0,0,1,0,-1,1,-1,-1,1};

using  E = tuple<int, int, int>;

int main(){
    int h,w;cin >> h >> w;
    vector<vector<int>> a(h, vector<int> (w - 1));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w - 1; j++) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> b(h - 1, vector<int> (w));
    for (int i = 0; i < h-1; i++) {
        for (int j = 0; j < w; j++) {
            cin >> b[i][j];
        }
    }
    priority_queue<E, vector<E>, greater<E>> pq;
    pq.push({0, 0, 0});
    vector<vector<int>> dp(h + 1, vector<int> (w + 1, INF));
    dp[0][0] = 0;
    while(not pq.empty()){
        auto [c, y, x] = pq.top();pq.pop();
        if(dp[y][x] < c) continue;
        if(x + 1 < w and chmin(dp[y][x + 1], c + a[y][x])){
            pq.push({dp[y][x + 1], y, x + 1});
        }
        if(x - 1 >= 0 and chmin(dp[y][x - 1], c + a[y][x - 1])){
            pq.push({dp[y][x - 1], y, x - 1});
        }
        if(y + 1 < h and chmin(dp[y + 1][x], c + b[y][x])){
            pq.push({dp[y + 1][x], y + 1, x});
        }
        for (int i = 1; i <= y; i++) {
            if(chmin(dp[y - i][x], c + i + 1)){
                pq.push({dp[y - i][x], y - i, x});
            }
        }
    }
    cout << dp[h - 1][w - 1] << endl;
    return 0;
}

// E - 潜入
#include <bits/stdc++.h>
using namespace std;
#define vec vector
using vi = vec<int>;
using PR = pair<int,int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int V; // 頂点数
vec<vec<PR>> G; // [from]<to, cost> 隣接リスト
int INF = 1e9;

vi dijkstra(int s){
	vi dist(V, INF);
	dist[s] = 0;
	priority_queue<PR, vec<PR>, greater<PR>> pq;
	pq.push({0, s});
	while(pq.size()){
		auto[from_d, from_v] = pq.top(); pq.pop();
		if(dist[from_v] < from_d) continue;
		for(auto[to_u, to_d]:G[from_v]){
			to_d += dist[from_v];
			if(dist[to_u] <= to_d) continue;
			dist[to_u] = to_d;
			pq.push({to_d, to_u});
		}
	}
	return dist;
}

int main(){
	int R, C; cin>>R>>C;

	auto rc2id = [&](int r, int c){ return r*C + c; };

	V = R*C*2;
	G.resize(V);

	int x, a, b;
	rep(r, R) rep(c, C-1){
		cin>>x;
		a = rc2id(r, c), b = rc2id(r, c+1);
		G[a].emplace_back(b, x), G[b].emplace_back(a, x);
	}

	rep(r, R-1) rep(c, C){
		cin>>x;
		G[rc2id(r, c)].emplace_back(rc2id(r+1, c), x);
	}

	rep(r, R) rep(c, C){
		a = rc2id(r, c), b = rc2id(r, c+R*C);
		G[a].emplace_back(b, 1), G[b].emplace_back(a, 0);
		if(r != R-1) G[rc2id(r+1, c+R*C)].emplace_back(rc2id(r, c+R*C), 1);
	}

	cout<< dijkstra(0)[rc2id(R-1,C-1)] <<endl;
}
