#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(vector<bool>::reference b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
int main() {
	int R, C;
	scanf("%d%d", &R, &C);
	vector<vector<int>> A(R, vector<int>(C - 1)), B(R - 1, vector<int>(C));
	for (int r = 0; r < R; ++r) {
		for (int i = 0; i + 1 < C; ++i) scanf("%d", &A[r][i]);
	}
	for (int r = 0; r + 1 < R; ++r) {
		for (int i = 0; i < C; ++i) scanf("%d", &B[r][i]);
	}
	const int INF = 1e9;
	typedef pair<ll, array<int, 3>> Pair;
	priority_queue<Pair, vector<Pair>, greater<Pair>> pq;
	vector<vector<vector<int>>> dist(R, vector<vector<int>>(C, vector<int>(2, INF)));
	dist[0][0][0] = 0;
	pq.push({0, {0, 0, 0}});
	auto enq = [&](int r, int c, int t, int ndist) {
		db(r, c, t, ndist);
		if (ndist < dist[r][c][t]) {
			dist[r][c][t] = ndist;
			pq.push({ndist, {r, c, t}});
		}
	};
	while (!pq.empty()) {
		auto u = pq.top().second;
		int cdist = pq.top().first;
		pq.pop();
		int r = u[0], c = u[1], t = u[2];
		db(u, cdist);
		if (r == R - 1 && c == C - 1) {
			printf("%d\n", cdist);
			return 0;
		}
		if (cdist > dist[r][c][t]) continue;
		if (c + 1 < C) enq(r, c + 1, 0, cdist + A[r][c]);
		if (c > 0) enq(r, c - 1, 0, cdist + A[r][c - 1]);
		if (r + 1 < R) enq(r + 1, c, 0, cdist + B[r][c]);
		enq(r, c, 1, cdist + 1);
		if (t == 1 && r > 0) enq(r - 1, c, t, cdist + 1);
	}
}

// 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;
}
