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

int main() {
    int64_t R, C;
    cin >> R >> C;
    vector<vector<int64_t>> A(R, vector<int64_t>(C - 1));
    vector<vector<int64_t>> B(R - 1, vector<int64_t>(C));
    for (int64_t i = 0; i < R; i++) {
        for (int64_t j = 0; j < C - 1; j++) {
            cin >> A[i][j];
        }
    }
    for (int64_t i = 0; i < R - 1; i++) {
        for (int64_t j = 0; j < C; j++) {
            cin >> B[i][j];
        }
    }

    vector<vector<int64_t>> cost(R, vector<int64_t>(C, LLONG_MAX));
    struct Element {
        int64_t r, c, cost;
        bool operator>(const Element& rhs) const {
            return cost > rhs.cost;
        }
    };
    priority_queue<Element, vector<Element>, greater<Element>> pq;

    pq.push({ 0, 0, cost[0][0] = 0 });
    while (!pq.empty()) {
        Element t = pq.top();
        pq.pop();
        if (t.cost > cost[t.r][t.c]) {
            continue;
        }

        if (t.r == R - 1 && t.c == C - 1) {
            break;
        }

        if (t.c < C - 1) {
            int64_t new_cost = t.cost + A[t.r][t.c];
            if (new_cost < cost[t.r][t.c + 1]) {
                pq.push({ t.r, t.c + 1, cost[t.r][t.c + 1] = new_cost });
            }
        }
        if (t.c > 0) {
            int64_t new_cost = t.cost + A[t.r][t.c - 1];
            if (new_cost < cost[t.r][t.c - 1]) {
                pq.push({ t.r, t.c - 1, cost[t.r][t.c - 1] = new_cost });
            }
        }
        if (t.r < R - 1) {
            int64_t new_cost = t.cost + B[t.r][t.c];
            if (new_cost < cost[t.r + 1][t.c]) {
                pq.push({ t.r + 1, t.c, cost[t.r + 1][t.c] = new_cost });
            }
        }
        for (int64_t i = 1; i <= t.r; i++) {
            int64_t new_cost = t.cost + 1 + i;
            if (new_cost < cost[t.r - i][t.c]) {
                pq.push({ t.r - i, t.c, cost[t.r - i][t.c] = new_cost });
            }
        }
    }

    cout << cost[R - 1][C - 1] << endl;
}
// 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;
}
