#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;         
typedef pair<int, int> P;
 
const int maxn = 500 + 10;        
const int M_MAX = 10 * maxn * maxn;
const int mod = 1e9 + 7;
const LL INF = 0x3f3f3f3f;    
const double eps = 1e-6;      

struct edge {
    int to, cost, next;
}e[5000010];

int n, m;
int h[1000010], d[1000010], len = 1;

int p(int x, int y) { return (x - 1) * m + y; }

void addedge(int v, int u, int cost) {
    e[len].to = u;
    e[len].cost = cost;
    e[len].next = h[v];
    h[v] = len++;
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j < m; j++) {
            int c; cin >> c;
            addedge(p(i, j) , p(i, j + 1), c);
            addedge(p(i,j+1), p(i, j), c);
        }
    }
    for(int i = 1; i < n; i++) {
        for(int j = 1; j <= m; j++) {
            int c; cin >> c;
            addedge(p(i, j), p(i+1, j), c);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            addedge(p(i, j), p(i, j) + n*m, 1);
            addedge(p(i,j) + n*m, p(i,j), 0);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            addedge(p(i+1, j) + n*m, p(i,j) + n*m, 1);
        }
    }
    for(int i = 1; i <= 2 * n * m; i++) d[i] = INF;
    d[1] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(P(0, 1));
    while(!que.empty()) {
        P pe = que.top(); que.pop();
        int v = pe.second;
        if(d[v] < pe.first) continue;
        for(int i = h[v]; i; i = e[i].next) {
            if(d[e[i].to] > e[i].cost + d[v]) {
                d[e[i].to] = e[i].cost + d[v];
                que.emplace(P(d[e[i].to], e[i].to));
            }
        }
    }
    cout << d[n*m] << endl;
}   
 
int main() {
    ios::sync_with_stdio(false);
    //srand(time(NULL));    //更新种子
    solve();
    return 0;
}  
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

using ll = long long;
using namespace std;

template<typename A, typename B>
bool chmin(A &a, const B b) {
  if (a <= b) return false;
  a = b;
  return true;
}

template<typename A, typename B>
bool chmax(A &a, const B b) {
  if (a >= b) return false;
  a = b;
  return true;
}

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&...args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

constexpr int mod = 1'000'000'007; //1e9+7(prime number)
constexpr int INF = 1'000'000'000; //1e9
constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18
constexpr int SIZE = 510;

int A[SIZE][SIZE], B[SIZE][SIZE];
int dp[SIZE][SIZE][2];

int main() {
  int H, W;

  scanf("%d%d", &H, &W);

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W - 1; j++) {
      scanf("%d", A[i] + j);
      // A[i][j] = rand() % 1000;
    }
  }

  for (int i = 0; i < H - 1; i++) {
    for (int j = 0; j < W; j++) {
      scanf("%d", B[i] + j);
      // B[i][j] = rand() % 1000;
    }
  }

  for (int j = 0; j <= H; j++) {
    for (int k = 0; k <= W; k++) {
      dp[j][k][0] = dp[j][k][1] = INF;
    }
  }

  dp[0][0][0] = 0;

  for (int i = 0; i <= W; i++) {
    for (int j = 0; j < H; j++) {
      for (int k = 0; k < W; k++) {
        if (k + 1 < W) chmin(dp[j][k + 1][0], dp[j][k][0] + A[j][k]);
      }
      for (int k = W - 1; k >= 0; k--) {
        if (k) chmin(dp[j][k - 1][0], dp[j][k][0] + A[j][k - 1]);
      }
      for (int k = 0; k < W; k++) {
        if (j + 1 < H) chmin(dp[j + 1][k][0], dp[j][k][0] + B[j][k]);
      }
    }
    for (int j = H - 1; j >= 0; j--) {
      for (int k = 0; k < W; k++) {
        if (j) {
          chmin(dp[j - 1][k][1], dp[j][k][0] + 2);
          chmin(dp[j - 1][k][1], dp[j][k][1] + 1);
        }
        chmin(dp[j][k][0], dp[j][k][1]);
      }
    }
  }

  int ans = INF;

  for (int i = 0; i <= W; i++) {
    chmin(ans, dp[H - 1][W - 1][0]);
  }

  printf("%d\n", ans);

  return 0;
}