#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)

bool dp[80+5][80+5][(160*80)+5][2];

void solve(){
    ll h, w;
    cin>>h>>w;
    ll a[h][w], b[h][w];
    loop(i,0,h){
        loop(j,0,w){
            cin>>a[i][j];
        }
    }
    loop(i,0,h){
        loop(j,0,w){
            cin>>b[i][j];
        }
    }
    for(ll i=0; i<80+5; i++){
        loop(j,0,80+5){
            loop(k,0,(160*80)+5){
                loop(l,0,2){
                    dp[i][j][k][l] = 0;
                }
            }
        }
    }
    // print("pp");
    // ret;
    dp[0][0][abs(a[0][0]-b[0][0])][0] = dp[0][0][abs(a[0][0]-b[0][0])][1] = 1;
    for(ll i=0; i<h; i++){
        for(ll j=0; j<w; j++){
            if(i == 0 && j == 0) continue;
            for(ll diff = 0; diff < (160*80)+5; diff++){
                ll o1 = diff - a[i][j] + b[i][j];
                if(o1 >= 0) {
                    if(i-1 >= 0) dp[i][j][diff][0] = dp[i][j][diff][0] || dp[i-1][j][o1][0];
                    if(j-1 >= 0) dp[i][j][diff][0] = dp[i][j][diff][0] || dp[i][j-1][o1][0];
                }
                else {
                    if(i >= 1) dp[i][j][diff][0] = dp[i][j][diff][0] || dp[i-1][j][-o1][1];
                    if(j >=1) dp[i][j][diff][0] = dp[i][j][diff][0] || dp[i][j-1][-o1][1];                    
                }
                ll o2 = diff + a[i][j] - b[i][j];
                if(o2 >= 0) {
                    if(i>=1) dp[i][j][diff][0] = dp[i][j][diff][0] || dp[i-1][j][o2][0];
                    if(j>=1)dp[i][j][diff][0] = dp[i][j][diff][0] || dp[i][j-1][o2][0];
                }
                else {
                    if(i>=1) dp[i][j][diff][0] = dp[i][j][diff][0] || dp[i-1][j][-o2][1];
                    if(j>=1)dp[i][j][diff][0] = dp[i][j][diff][0] || dp[i][j-1][-o2][1]; 
                }


                o1 = diff + a[i][j] - b[i][j];
                if(o1 >= 0){
                    if(i>=1) dp[i][j][diff][1] = dp[i][j][diff][1] || dp[i-1][j][o1][1];
                    if(j>=1)dp[i][j][diff][1] = dp[i][j][diff][1] || dp[i][j-1][o1][1];
                }
                else {
                    if(i>=1) dp[i][j][diff][1] = dp[i][j][diff][1] || dp[i-1][j][-o1][0];
                    if(j>=1)dp[i][j][diff][1] = dp[i][j][diff][1] || dp[i][j-1][-o1][0];
                }
                o2 = diff - a[i][j] + b[i][j];
                if(o2 >= 0){
                    if(i>=1) dp[i][j][diff][1] = dp[i][j][diff][1] || dp[i-1][j][o2][1];
                    if(j>=1)dp[i][j][diff][1] = dp[i][j][diff][1] || dp[i][j-1][o2][1];
                }
                else {
                    if(i>=1) dp[i][j][diff][1] = dp[i][j][diff][1] || dp[i-1][j][-o2][0];
                    if(j>=1)dp[i][j][diff][1] = dp[i][j][diff][1] || dp[i][j-1][-o2][0];
                }

            }
        }
    }
    for(ll diff = 0; diff < (160*80)+5; diff++){
        if(dp[h-1][w-1][diff][0] || dp[h-1][w-1][diff][1]){
            print(diff);
            ret;
        }
    }
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }

}


Measured memory_bytes: 181120