#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int h,w;
int a[85][85];
bool ok[85][85][6500];

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int k;
            cin >> k;
            a[i][j] = abs(a[i][j] - k);
        }
    }
    ok[0][0][a[0][0]] = 1;
    ok[h-1][w-1][a[h-1][w-1]] = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
        pair<int,int> p = {i,j};
        if (i + j + 1 > (h + w - 1) / 2) continue;
        int th = p.first + 1;
        int tw = p.second + 1;
        for (int s = 0; s < 6500; s++) {
            if (!ok[p.first][p.second][s]) continue;
            if (th < h) {
                ok[th][p.second][abs(s + a[th][p.second])] = 1;
                ok[th][p.second][abs(s - a[th][p.second])] = 1;
            }
            if (tw < w) {
                ok[p.first][tw][abs(s + a[p.first][tw])] = 1;
                ok[p.first][tw][abs(s - a[p.first][tw])] = 1;
            }
        }
    }
    }
    for (int i = h - 1; i >= 0; i--) {
        for (int j = w - 1; j >= 0; j--) {
        pair<int,int> p = {i,j};
        if (i + j - 1 <= (h + w - 1) / 2) continue;
        int th = p.first - 1;
        int tw = p.second - 1;
        for (int s = 0; s < 6500; s++) {
            if (!ok[p.first][p.second][s]) continue;
            if (th >= 0) {
                ok[th][p.second][abs(s + a[th][p.second])] = 1;
                ok[th][p.second][abs(s - a[th][p.second])] = 1;
            }
            if (tw >= 0) {
                ok[p.first][tw][abs(s + a[p.first][tw])] = 1;
                ok[p.first][tw][abs(s - a[p.first][tw])] = 1;
            }
        }
    }
    }
    int k = (h + w - 1) / 2;
    int ans = 1e9;
    int inf = 1e9;
    for (int i = 0; i < h; i++) {
        int j = k - i;
        if (j >= w || j < 0) continue;
        vector<int> v1;
        for (int s = 0; s < 6500; s++) {
            if (ok[i][j][s])
                v1.push_back(s);
        }
        if (i + 1 < h) {
            vector<int> v2;
            v2.push_back(-inf);
            for (int s = 0; s < 6500; s++) {
                if (ok[i+1][j][s])
                    v2.push_back(s);
            }
            v2.push_back(inf);
            ans = min(ans,v1[0] + v2[1]);
            for (int i = 0; i < v1.size(); i++) {
                auto p = lower_bound(v2.begin(),v2.end(),v1[i]);
                int aa = *p;
                p--;
                int bb = *p;
                ans = min(ans, min(abs(v1[i] - aa), abs(v1[i] - bb)));
            }
        }
        if (j + 1 < w) {
            vector<int> v2;
            v2.push_back(-inf);
            for (int s = 0; s < 6500; s++) {
                if (ok[i][j+1][s])
                    v2.push_back(s);
            }
            v2.push_back(inf);
            ans = min(ans,v1[0] + v2[1]);
            for (int i = 0; i < v1.size(); i++) {
                auto p = lower_bound(v2.begin(),v2.end(),v1[i]);
                int aa = *p;
                p--;
                int bb = *p;
                // cout << i << " " << aa << " " << bb << endl;
                ans = min(ans, min(abs(v1[i] - aa), abs(v1[i] - bb)));
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 45184