#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const char newl = '\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;
  vl a(n), b(n), d(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) {
    if(i%2==0) d[i] = a[i]-b[i];
    else d[i] = b[i]-a[i];
  }

  vpl vec;
  rep(i, n) vec.push_back(pl (d[i], i));
  sort(all(vec), greater<pl>());
  vb choose_a(n, 0);
  rep(i, n) {
    ll num = vec[i].second;
    if(i < n/2 && num%2==0) choose_a[num] = 1;
    if(i >= n/2 && num%2==1) choose_a[num] = 1; 
  }
  ll ans=0;
  rep(i, n) {
    if(choose_a[i]) ans += a[i];
    else ans += b[i];
  }
  cout << ans << newl;
  return 0;
}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

struct dijkstra {

  ll N;
  struct edge { ll to, d; };
  vector<vector<edge>> adj;
  vector<ll> minlen;

  dijkstra(ll n) { N = n; adj.resize(N); minlen.assign(N,LLINF); }
  ll operator[](const ll &x) const { return minlen[x]; }

  void add_edge(ll from, ll to, ll d){
    adj[from].push_back({to,d});
  }
  vector<ll> calc(ll n=0) {
    auto c = [](const p_ll &x, const p_ll &y){return x.second>y.second;};
    priority_queue<p_ll, vector<p_ll>, decltype(c)> q(c);
    minlen[n] = 0; q.push(make_pair(n,0));
    while(q.size()) {
      p_ll now = q.top(); q.pop();
      ll np = now.first, nd = now.second;
      if (nd>minlen[np]) continue;
      for (auto x: adj[np]) {
        if (minlen[x.to]<=minlen[np]+x.d) continue;
        q.push(make_pair(x.to, minlen[np]+x.d));
        minlen[x.to] = minlen[np]+x.d;
      }
    }
    return minlen;
  }

};

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

ll R, C;
ll gid(ll i, ll j, bool ura) { return i*C + j + ura*(R*C); }

int main() {
  cin >> R >> C;
  ll A[R][C-1]; rep(i,R) rep(j,C-1) cin >> A[i][j];
  ll B[R-1][C]; rep(i,R-1) rep(j,C) cin >> B[i][j];

  dijkstra ds(R*C*2);
  rep(i,R) rep(j,C-1) {
    ds.add_edge(gid(i,j,false), gid(i,j+1,false), A[i][j]);
    ds.add_edge(gid(i,j+1,false), gid(i,j,false), A[i][j]);
  }
  rep(i,R-1) rep(j,C) {
    ds.add_edge(gid(i,j,false), gid(i+1,j,false), B[i][j]);
    ds.add_edge(gid(i+1,j,true), gid(i,j,true), 1);
  }
  rep(i,R) rep(j,C) {
    ds.add_edge(gid(i,j,false), gid(i,j,true), 1);
    ds.add_edge(gid(i,j,true), gid(i,j,false), 0);
  }
  

  vector<ll> d = ds.calc();
  ll result = ds[gid(R-1,C-1,false)];
  cout << result << endl;
  return 0;
}