#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;
template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}
template<typename T>
void cout_mat(vector<vector<T>  > &mat){
    for(int i=0; i<mat.size(); i++){
        vector<T> vec = mat[i];
        cout_vec(mat[i]);
    }
}

int main(){
    int H, W;
    cin >> H >> W;

    vector<vector<int>> grid(H,vector<int>(W,0));
    for(auto &line:grid){
        for(auto &a:line){
            cin >> a;
        }
    }

    for(auto &line:grid){
        for(auto &a:line){
            int x;
            cin >> x;
            a-=x;
        }
    }
    int N=160*160;

    vector<vector<vector<int>>> dp(H+1,vector<vector<int>>(W+1,vector<int>(N+1,0)));
    dp[0][0][N/2]=1;

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int diff=grid[i][j];
            for(int k=0; k<=N; k++){
                if(0<=k+diff && k+diff<=N){
                    dp[i+1][j][k+diff]|=dp[i][j][k];
                    dp[i][j+1][k+diff]|=dp[i][j][k];
                }
                if(0<=k-diff && k-diff<=N){
                    dp[i][j+1][k-diff]|=dp[i][j][k];
                    dp[i+1][j][k-diff]|=dp[i][j][k];
                }
            }
        }
    }

    for(int i=0; i<N; i++){
        if(dp[H][W-1][N/2-i] || dp[H][W-1][N/2+i]){
            cout << i << endl;
            return 0;
        }
    }

}
#include <bits/stdc++.h>
#define fi first
#define se second
#define ii pair<int, int>
#define int long long
using namespace std;

const int INF = 1e9;
int n, m;
int ans = INF;
int a[85][85], b[85][85];
bool f[85][85][52000];

void attempt(int i, int j, int diff)
{

    if (i == n && j == m)
    {
        ans = min(ans, abs(diff + a[i][j] - b[i][j]));
        ans = min(ans, abs(diff - a[i][j] + b[i][j]));
        return;
    }
    if (f[i][j][diff])
        return;
    f[i][j][diff] = 1;

    if (i < n){
        attempt(i+1, j, abs(diff + a[i][j] - b[i][j]));
        attempt(i+1, j, abs(diff - a[i][j] + b[i][j]));
    }
    if (j < m){
        attempt(i, j+1, abs(diff + a[i][j] - b[i][j]));
        attempt(i, j+1, abs(diff - a[i][j] + b[i][j]));
    }

}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

//    freopen("in.inp", "r", stdin);
//    freopen("out.out", "w", stdout);

    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> b[i][j];

    attempt(1, 1, 0);
    cout << ans;
}
