#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using PLL = pair<LL,LL>;
using VPI = vector<PII>;
using VPL = vector<PLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i,m,n) for(LL i=(m);i<(n);i++)
#define RREP(i,m,n) for(int i=(m);i>=(n);i--)

int main(){
  LL n,k,ans=0;
  cin >> n >> k;
  
  REP(ab,2,2*n+1){
    LL cd = ab - k;
    if(2<=cd && cd<=2*n){
      LL count_ab = min(ab-1, 2*n-ab+1);
      LL count_cd = min(cd-1, 2*n-cd+1);
      ans += count_ab * count_cd;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

ll R,C;

class Dijkstra{
    /*
    Copyright (c) 2021 0214sh7
    https://github.com/0214sh7/library/
    */
    private:
    typedef std::pair<long long,int> P;
    std::vector<std::vector<P>> G;
    int V;
    //long long INF = (1LL<<61);
    std::priority_queue<P,std::vector<P>,std::greater<P>> que;
    
    public:
    void init(int N,std::vector<std::pair<std::pair<int,int>,long long>> edge){
        //頂点数を決定する
        V=N;
        
        //辺集合を扱いやすい形式に変換する
        G.resize(V);
        for(int i=0;i<edge.size();i++){
            int from=edge[i].first.first,to=edge[i].first.second;
            long long cost=edge[i].second;
            G[from].push_back({cost,to});
        }
    }
    
    Dijkstra(int N,std::vector<std::pair<std::pair<int,int>,long long>> edge){
        init(N,edge);
    }

    std::vector<long long> solve(int s){
        std::vector<long long> d;
        //INFで初期化する
        for(int i=0;i<V;i++){
            d.push_back(INF);
        }
        d[s]=0;
        que.push({0,s});
        //queは{cost,to}をコストが小さい順に出す
        while(!que.empty()){
            P p = que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            for(int i=0;i<G[v].size();i++){
                P e = G[v][i];
                if(d[e.second]>d[v]+e.first){
                    d[e.second] = d[v]+e.first;
                    que.push({d[e.second],e.second});
                }
            }
            
            //新造
            
            for(ll i=1;v-i*C>=0;i++){
                if(d[v-i*C]>d[v]+1+i){
                    d[v-i*C] = d[v]+1+i;
                    que.push({d[v-i*C],v-i*C});
                }
            }
            
        }
        return d;
    }
};

int main(void){
    
    
    vector<vector<ll>> A,B;
    
    cin >> R >> C;
    A.resize(R);
    B.resize(R-1);
    
    REP(i,R){
        REP(j,C-1){
            ll a;
            cin >> a;
            A[i].push_back(a);
        }
    }
    REP(i,R-1){
        REP(j,C){
            ll b;
            cin >> b;
            B[i].push_back(b);
        }
    }
    
    vector<pair<pair<int,int>,long long>> E;
    REP(i,R){
        REP(j,C-1){
            E.push_back({ {i*C+j,i*C+j+1},A[i][j]});
            E.push_back({ {i*C+j+1,i*C+j},A[i][j]});
        }
    }
    REP(j,C){
        REP(i,R-1){
            E.push_back({ {i*C+j,(i+1)*C+j},B[i][j]});
        }
    }
    
    Dijkstra dijkstra(R*C,E);
    vector<ll> D = dijkstra.solve(0);
    /*
    REP(i,R*C){
        cout << D[i] << " ";
        if((i+1)%C==0)cout << endl;
    }*/
    
    cout << D[R*C-1] << endl;
    
    return 0;
}
