#include <bits/stdc++.h>

using namespace std;
#define ull unsigned long long
#define ll long long
const int inf = 1e6;
const int MAXN = 2e5 + 10;
vector<vector<pair<int, int>>> data(15, vector<pair<int, int>>());
ull mod = 1e9 + 7;
vector<ull> arr;
int dp[80][80][160 * 80][2];
int mass[80][80];

void solve() {
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> mass[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int a;
            cin >> a;
            mass[i][j] -= a;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int s=0;s<160*80;s++){
                for(int k=0;k<2;k++){
                    dp[i][j][s][k]=inf;
                }
            }
        }
    }
    for (int i = 0; i < 160 * 80; i++) {
        for (int k = 0; k < 2; k++) {
            dp[h - 1][w - 1][i][k] = i * ((k == 1) ? -1 : 1) + mass[h - 1][w - 1];
            if(abs(i * ((k == 1) ? -1 : 1) - mass[h - 1][w - 1])<dp[h - 1][w - 1][i][k] ){
                dp[h - 1][w - 1][i][k]=i * ((k == 1) ? -1 : 1) - mass[h - 1][w - 1];
            }
        }
    }
    for (int j = w - 2; j >= 0; j--) {
        for (int i = 0; i < 160 * 80; i++) {
            for (int k = 0; k < 2; k++) {
                int what = i * ((k == 1) ? -1 : 1) + mass[h - 1][j];
                if (what < 160 * 80 && what >= 0) {
                    dp[h - 1][j][i][k] = dp[h - 1][j + 1][what][0];
                } else if (what > -160 * 80 && what < 0) {
                    dp[h - 1][j][i][k] = dp[h - 1][j + 1][-what][1];
                } else {
                    dp[h - 1][j][i][k] = inf;
                }
                what = i * ((k == 1) ? -1 : 1) - mass[h - 1][j];
                if (what < 160 * 80 && what >= 0) {
                    if(abs(dp[h - 1][j + 1][what][0])<abs(dp[h - 1][j][i][k])){
                        dp[h - 1][j][i][k]=dp[h - 1][j + 1][what][0];
                    }
                } else if (what > -160 * 80 && what < 0) {
                    if(abs(dp[h - 1][j + 1][-what][1])<abs(dp[h - 1][j][i][k])){
                        dp[h - 1][j][i][k]=dp[h - 1][j + 1][-what][1];
                    }
                } else {
                    dp[h - 1][j][i][k] = inf;
                }


            }
        }
    }
    for (int j = h - 2; j >= 0; j--) {
        for (int i = 0; i < 160 * 80; i++) {
            for (int k = 0; k < 2; k++) {
                int what = i * ((k == 1) ? -1 : 1) + mass[j][w - 1];
                if (what < 160 * 80 && what >= 0) {
                    dp[j][w - 1][i][k] = dp[j + 1][w - 1][what][0];
                } else if (what > -160 * 80 && what < 0) {
                    dp[j][w - 1][i][k] = dp[j + 1][w - 1][-what][1];
                } else {
                    dp[j][w - 1][i][k] = inf;
                }
                what = i * ((k == 1) ? -1 : 1) - mass[j][w - 1];
                if (what < 160 * 80 && what >= 0) {
                    if(abs(dp[j + 1][w - 1][what][0])< dp[j][w - 1][i][k])dp[j][w - 1][i][k] = dp[j + 1][w - 1][what][0];

                } else if (what > -160 * 80 && what < 0) {
                    if(abs(dp[j + 1][w - 1][-what][1])< dp[j][w - 1][i][k])dp[j][w - 1][i][k] = dp[j + 1][w - 1][-what][1];
                } else {
                    dp[j][w - 1][i][k] = inf;
                }
            }
        }
    }

    for (int j = h - 2; j >= 0; j--) {
        for (int i = w - 2; i >= 0; i--) {
            for (int s = 0; s < 160 * 80; s++) {
                for (int k = 0; k < 2; k++) {
                    int begin=s * ((k == 1) ? -1 : 1) + mass[j][i];
                    if(begin<160*80 && begin>=0){
                        int down=dp[j+1][i][begin][0];
                        int right=dp[j][i+1][begin][0];
                        if(abs(down)<abs(right)){
                            swap(down, right);
                        }
                        dp[j][i][s][k]=right;
                    }
                    else if(begin>-160*80 && begin<0){
                        int down=dp[j+1][i][-begin][1];
                        int right=dp[j][i+1][-begin][1];
                        if(abs(down)<abs(right)){
                            swap(down, right);
                        }
                        dp[j][i][s][k]=right;
                    }
                    else {
                        dp[j][i][s][k]=inf;
                    }

                    begin=s * ((k == 1) ? -1 : 1) - mass[j][i];
                    if(begin<160*80 && begin>=0){
                        int down=dp[j+1][i][begin][0];
                        int right=dp[j][i+1][begin][0];
                        if(abs(down)<abs(right)){
                            swap(down, right);
                        }
                        if(abs(right)<dp[j][i][s][k]) dp[j][i][s][k]=right;
                    }
                    else if(begin>-160*80 && begin<0){
                        int down=dp[j+1][i][-begin][1];
                        int right=dp[j][i+1][-begin][1];
                        if(abs(down)<abs(right)){
                            swap(down, right);
                        }
                        if(abs(right)<dp[j][i][s][k]) dp[j][i][s][k]=right;
                    }
                    else {
                        dp[j][i][s][k]=inf;
                    }
                }
            }
        }
    }
    cout<<abs(dp[0][0][0][0]);


}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n = 1;
    for (int i = 0; i < n; i++) solve();
    return 0;
}

Measured memory_bytes: 640384