#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll x,h,w,ans=16384;
ll num[80][80];
bool flags[81][81][26000];
void Main(){
    cin>>h>>w;
    For(i,0,h){
        For(j,0,w){
            cin>>num[i][j];
        }
    }
    For(i,0,h){
        For(j,0,w){
            cin>>x;
            num[i][j]-=x;
        }
    }
    For(i,0,81){
        For(k,0,26000){
            flags[i][0][k]=false;
            flags[0][i][k]=false;
        }
    }
    flags[0][1][13000]=true;
    For(i,0,h){
        For(j,0,w){
            ll a=num[i][j];
            For(k,0,26000){
                flags[i+1][j+1][k]=flags[i][j+1][k-a]||flags[i][j+1][k+a]||flags[i+1][j][k-a]||flags[i+1][j][k+a];
            }
        }
    }
    For(k,0,26000){
        if(flags[h][w][k]) ans=min(ans,abs(k-13000));
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}
