#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = numeric_limits<ll>::max() / 4;
// const int INF = numeric_limits<int>::max() / 4;


int main() {
	// ll N;
	int R, C;
	cin >> R >> C;
	vector<vector<int> > A(R,vector<int>(C,0));
	vector<vector<int> > B(R,vector<int>(C,0));
	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];
		}
	}



	vector<vector<ll> > X(R*2,vector<ll>(C,INF));
	
	multimap<int,pair<int,int> > P;
	X[0][0] = 0;
	P.insert(make_pair(0,make_pair(0,0)));
	while(!P.empty()){
		auto p = P.begin();
		P.erase(p);
		int r = p->second.first;
		int c = p->second.second;
		int x = X[r][c];
		if(R <= r){
			r -= R;
			if(0 < r){
				if(x + 1 < X[r-1][c]){
					X[r-1][c] = x + 1;
					P.insert(make_pair(X[r-1][c],make_pair(r-1,c)));
				}
				if(x + 1 < X[r-1+R][c]){
					X[r-1+R][c] = x + 1;
					P.insert(make_pair(X[r-1+R][c],make_pair(r-1+R,c)));
				}
			}
			continue;
		}
		if(c < C - 1){
			if(x + A[r][c] < X[r][c+1]){
				X[r][c+1] = x + A[r][c];
				P.insert(make_pair(X[r][c+1],make_pair(r,c+1)));
			}
		}
		if(0 < c){
			if(x + A[r][c-1] < X[r][c-1]){
				X[r][c-1] = x + A[r][c-1];
				P.insert(make_pair(X[r][c-1],make_pair(r,c-1)));
			}
		}
		if(r < R -1){
			if(x + B[r][c] < X[r+1][c]){
				X[r+1][c] = x + B[r][c];
				P.insert(make_pair(X[r+1][c],make_pair(r+1,c)));
			}
		}
		if(x + 1 < X[r + R][c]){
			X[r + R][c] = x + 1;
			P.insert(make_pair(X[r+R][c],make_pair(r +R,c)));
		}
	}
	cout << X[R-1][C-1] << endl;
	return(0);
}

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REP(i,k,n) for(ll i=k;i<ll(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end())
#define decimal cout<<fixed<<setprecision(10)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)
using ll=long long;
using P=pair<ll,ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
constexpr ll inf=1001001001001001;
constexpr int INF=1001001001;
constexpr int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
void YesNo(bool b){if(b)out("Yes");else out("No");}
void yesno(bool b){if(b)out("yes");else out("no");}
void YESNO(bool b){if(b)out("YES");else out("NO");}
ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;}

int main(){
    int r,c;
    cin>>r>>c;
    int n=r*c;
    vector<vector<P>> edge(2*n);
    rep(i,n){
        edge[i].eb(P(i+n,1));
        edge[i+n].eb(P(i,0));
    }
    rep(i,r)rep(j,c-1){
        int a; cin>>a;
        edge[i*c+j].eb(P(i*c+j+1,a));
        edge[i*c+j+1].eb(P(i*c+j,a));
    }
    rep(i,r-1)rep(j,c){
        int b; cin>>b;
        edge[i*c+j].eb(P((i+1)*c+j,b));
        edge[(i+1)*c+j+n].eb(P(i*c+j+n,1));
    }
    vi cost(2*n,INF);
    SPQ(P) q;
    q.push(P(0,0));
    cost[0]=0;
    while(!q.empty()){
        ll x=q.top().se,z=q.top().fi;
        q.pop();
        if(cost[x]<z) continue;
        for(P y:edge[x]){
            if(chmin(cost[y.fi],cost[x]+y.se)){
                q.push(P(cost[y.fi],y.fi));
            }
        }
    }
    out(cost[r*c-1]);
    //rep(i,2*n) outvp(edge[i]);
}