#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=81;
const int z=12800;
bool dp[81][81][25601];
int n,m;
int a[max_n][max_n],b[max_n][max_n];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)scanf("%d",&b[i][j]);
    }
    dp[1][1][a[1][1]-b[1][1]+z]=dp[1][1][b[1][1]-a[1][1]+z]=true;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            for(int k=0;k<=25600;k++){
                if(dp[i][j][k]==false)continue;
                if(i+1<=n)dp[i+1][j][k+a[i+1][j]-b[i+1][j]]=dp[i+1][j][k-a[i+1][j]+b[i+1][j]]=true;
                if(j+1<=m)dp[i][j+1][k+a[i][j+1]-b[i][j+1]]=dp[i][j+1][k-a[i][j+1]+b[i][j+1]]=true;
            }
        }
    }
    int ans=1000000000;
    for(int i=0;i<=25600;i++)if(dp[n][m][i])ans=min(ans,abs(i-z));
    printf("%d\n",ans);
    return 0;
}