/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;
typedef pair<int, int> P;

class E {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int R, C;
        cin >> R >> C;
        vector<vector<int>> A(R, vector<int>(C - 1));
        vector<vector<int>> B(R - 1, vector<int>(C));
        REP(i, R) REP(j, C - 1) cin >> A[i][j];
        REP(i, R - 1) REP(j, C) cin >> B[i][j];

        vector<int> dist(R * C * 2, INF);
        dist[0] = 0;
        priority_queue<P, vector<P>, greater<>> pq;
        pq.push({0, 0});
        while (!pq.empty()) {
            int cost, v;
            tie(cost, v) = pq.top();
            pq.pop();
            //cout << v << ":" << cost << endl;
            int x = v % R;
            int y = v / R;
            if (v >= R * C) {
                if (x - 1 >= 0) {
                    int nv = R * y + x - 1;
                    if (cost + 1 < dist[nv]) {
                        dist[nv] = cost;
                        pq.push({cost + 1, nv});
                    }
                }
                int nv = v - R * C;
                if (cost < dist[nv]) {
                    dist[nv] = cost;
                    pq.push({cost, nv});
                }
            } else {
                int nv = v + R * C;
                if (cost + 1 < dist[nv]) {
                    dist[nv] = cost + 1;
                    pq.push({cost + 1, nv});
                }
                if (y + 1 <= C - 1) {
                    nv = R * (y + 1) + x;
                    if (cost + A[x][y] < dist[nv]) {
                        dist[nv] = cost + A[x][y];
                        pq.push({cost + A[x][y], nv});
                    }
                }
                if (y - 1 >= 0) {
                    nv = R * (y - 1) + x;
                    if (cost + A[x][y - 1] < dist[nv]) {
                        dist[nv] = cost + A[x][y - 1];
                        pq.push({cost + A[x][y - 1], nv});
                    }
                }
                if (x + 1 <= R - 1) {
                    nv = R * y + x + 1;
                    if (cost + B[x][y] < dist[nv]) {
                        dist[nv] = cost + B[x][y];
                        pq.push({cost + B[x][y], nv});
                    }
                }
            }
        }
        cout << dist[R * C - 1] << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    E solver;
    solver.solve(in, out);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int to_int(string s){
    bool f=false;
    if(s[0]=='-'){
        f=true;
        s=s.substr(1);
    }
    int cnt=4;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='.'){
            s=s.substr(0,i)+s.substr(i+1);
            cnt-=(n-1-i);
            break;
        }
    }
    int res=stoi(s);
    for(int i=0;i<cnt;i++){
        res*=10;
    }
    if(f)res*=-1;
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    ll x,y,r;
    cin >> s; x=to_int(s);
    cin >> s; y=to_int(s);
    cin >> s; r=to_int(s);
    ll res=0;
    constexpr int N=10000;
    auto uo=[](ll x)->ll{
        if(x<=0){
            x-=(N-1);
            x+=abs(x)%N;
            return x;
        }
        x-=abs(x)%N;
        return x;
    };
    auto uoo=[](ll x)->ll{
        if(x<=0){
            x+=abs(x)%N;
            return x;
        }
        x+=(N-1);
        x-=abs(x)%N;
        return x;
    };
    for(ll i=-r;i<=r;){
        if(abs(y+i)%N!=0){
            i++; continue;
        }
        ll L=0,R=2e9;
        while(R-L>1){
            ll mid=(L+R)/2;
            if(mid*mid+i*i<=r*r){
                L=mid;
            }
            else{
                R=mid;
            }
        }
        // cout << i << endl;
        ll X=uo(x+L),XX=uoo(x-L);
        if(X>=XX)res+=(X-XX)/N+1;
        i+=N;
    }
    cout << res << endl;
}