#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>

using namespace std;

int R, C;
long long int A[520][520], B[520][520];

long long int INF = 99999999999999;

long long int dis[300000];

vector<int> Adj[300000];
vector<long long int> cost[300000];

priority_queue < pair<long long int, int> > PQ;

int used[300000];

int main(void) {

	cin >> R >> 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];
		}
	}

	int N = R*C;

	dis[0] = 0;
	for (int i = 1; i <= R*C; i++) { dis[i] = INF; }

	for (int i = 0; i <= R - 1; i++) {
		for (int j = 0; j <= C - 2; j++) {
			int k = i*C + j;
			int u = i*C + j + 1;
			Adj[k].push_back(u);
			cost[k].push_back(A[i][j]);
		}
	}

	for (int i = 0; i <= R - 1; i++) {
		for (int j = 1; j <= C - 1; j++) {
			int k = i*C + j;
			int u = i*C + j - 1;
			Adj[k].push_back(u);
			cost[k].push_back(A[i][j-1]);
		}
	}

	for (int i = 0; i <= R - 2; i++) {
		for (int j = 0; j <= C - 1; j++) {
			int k = i*C + j;
			int u = (i + 1)*C + j;
			Adj[k].push_back(u);
			cost[k].push_back(B[i][j]);
		}
	}

	for (int i = 1; i <= R - 1; i++) {
		for (int j = 0; j <= C - 1; j++) {
			int k = i*C + j;
			for (int y = 0; y <= i - 1; y++) {
				int u = y*C + j;
				Adj[k].push_back(u);
				cost[k].push_back(i - y + 1);
			}
		}
	}


	PQ.push(make_pair(dis[0], 0)); used[0] = 1;

	int g = (R - 1)*C + C - 1;

	pair<long long int, int> tmp;

	while (PQ.size() > 0) {
		tmp = PQ.top();
		PQ.pop();

		long long int D = -tmp.first;
		int pos = tmp.second;

		used[pos] = 1;

		if (dis[pos] != D) { continue; }

		if (pos == g) { break; }

		for (int v = 0; v < (int)Adj[pos].size();v++) {
			int y = Adj[pos][v];
			if (used[y] != 0) { continue; }
			if (D + cost[pos][v] < dis[y]) {
				dis[y] = D + cost[pos][v];
				PQ.push(make_pair(-dis[y], y));
			}
		}

	}

	
	cout << dis[g]<< endl;

	return 0;
}

#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#endif
#if __has_include(<atcoder/all>)
#include <atcoder/all>
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
#define rep(i, a, b) for(int i = (int)(a); i <= (int)(b); i++)
#define rrep(i, a, b) for(int i = (int)(a); i >= (int)(b); i--)
const int MOD = 1000000007;
const int MOD2 = 998244353;
const ll INF = 1e18;
const ld PI = acos(-1);

struct edge{
    int to,cost;
};

const int MXV = 1000000;//変更可
vector<edge> G[MXV];
vector<int> d(MXV, 1e9);
 
void dijkstra(int s){
    using Pair_for_edge = pair<int,int>;
    priority_queue<Pair_for_edge, vector<Pair_for_edge>, greater<Pair_for_edge>> pq;
    d[s] = 0;
    pq.push(Pair_for_edge(0, s));
    while(pq.size()){
        Pair_for_edge p = pq.top();
        pq.pop();
        int V = p.second;
        if(d[V] < p.first){
            continue;
        }
        rep(i,0,G[V].size()-1){
            edge e = G[V][i];
            if(d[e.to] > d[V] + e.cost){
                d[e.to] = d[V] + e.cost;
                pq.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int R,C;
    cin >> R >> C;
    vector<vector<int>> A(R,vector<int>(C-1)),B(R-1,vector<int>(C));
    rep(i,0,R-1){
        rep(j,0,C-2){
            cin >> A[i][j];
            int v=i+1000*j,u=i+1000*(j+1);
            edge e;
            e.cost=A[i][j];
            e.to=u;
            G[v].push_back(e);
            e.to=v;
            G[u].push_back(e);
        }
    }
    rep(i,0,R-2){
        rep(j,0,C-1){
            cin >> B[i][j];
            int v=i+1000*j,u=i+1+1000*j;
            edge e;
            e.cost=B[i][j];
            e.to=u;
            G[v].push_back(e);
            e.to=v;
            e.cost=2;
            while((1000+e.to)%1000!=999){
                G[u].push_back(e);
                //cout << e.cost << endl;
                e.cost++;
                e.to--;
            }
        }
    }
    dijkstra(0);
    cout << d[(R-1)+1000*(C-1)] << endl;
}