#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char buf[10000000], *ptr = buf - 1;
inline int readint(){
int n = 0;
char ch = *++ptr;
while(ch < ‘0‘ || ch > ‘9‘) ch = *++ptr;
while(ch <= ‘9‘ && ch >= ‘0‘){
n = (n << 1) + (n << 3) + ch - ‘0‘;
ch = *++ptr;
}
return n;
}
const int INF = 2147483647;
struct Edge{
int to, val, next;
Edge(){}
Edge(int _t, int _v, int _n): to(_t), val(_v), next(_n){}
}e[6000000];
int fir[2000000] = {0}, cnt = 0;
inline void ins(int u, int v, int w){
e[++cnt] = Edge(v, w, fir[u]); fir[u] = cnt;
e[++cnt] = Edge(u, w, fir[v]); fir[v] = cnt;
}
int n, m, nm;
struct Node{
int dis, idx;
Node(){}
Node(int _d, int _i): dis(_d), idx(_i){}
}t;
class cmp{
public:
bool operator () (const Node &a, const Node &b){
return a.dis > b.dis;
}
};
priority_queue<Node, vector<Node>, cmp> pq;
int S, T;
bool state[2000000];
int dis[2000000];
int dijkstra(){
for(int i = T; i; i--){
dis[i] = INF;
state[i] = false;
}
dis[S] = 0;
pq.push(Node(0, S));
int u, v;
while(!pq.empty()){
t = pq.top(); pq.pop();
if(state[t.idx]) continue;
u = t.idx;
state[u] = true;
for(int i = fir[u]; i; i = e[i].next){
v = e[i].to;
if(dis[v] > dis[u] + e[i].val){
dis[v] = dis[u] + e[i].val;
pq.push(Node(dis[v], v));
}
}
}
}
int main(){
fread(buf, sizeof(char), sizeof(buf), stdin);
n = readint();
m = readint();
if(n != 1 && m != 1){
nm = (n - 1) * (m - 1);
S = 2 * nm + 1;
T = S + 1;
int u, v;
for(int i = 1; i <= n; i++)
for(int j = 1; j < m; j++){
u = i == 1 ? T : (i - 2) * (m - 1) + j + nm;
v = i == n ? S : (i - 1) * (m - 1) + j;
ins(u, v, readint());
}
for(int i = 1; i < n; i++)
for(int j = 1; j <= m; j++){
u = j == 1 ? S : (i - 1) * (m - 1) + j - 1;
v = j == m ? T : (i - 1) * (m - 1) + j + nm;
ins(u, v, readint());
}
for(int i = 1; i < n; i++)
for(int j = 1; j < m; j++){
u = (i - 1) * (m - 1) + j;
v = u + nm;
ins(u, v, readint());
}
dijkstra();
printf("%d\n", dis[T]);
}
else{
int ans = INF;
if(m == 1) swap(n, m);
for(int i = 1; i < m; i++)
ans = min(ans, readint());
printf("%d\n", ans);
}
return 0;
}