#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=85,mx=12800,mod=1e9+7;
int f[N][N][2*mx+5];
int n,m;
int a[N][N],b[N][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]);
	f[1][1][a[1][1]-b[1][1]+mx]=1;
	f[1][1][-(a[1][1]-b[1][1])+mx]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			if(i==1&&j==1) continue;
			for(int k=-mx;k<=mx;k++) {
				if(k+a[i][j]-b[i][j]<=mx&&k+a[i][j]-b[i][j]>=-mx) 
					f[i][j][mx+k+a[i][j]-b[i][j]]|=(f[i-1][j][mx+k]|f[i][j-1][mx+k]);
				if(k-(a[i][j]-b[i][j])<=mx&&k-(a[i][j]-b[i][j])>=-mx) 
					f[i][j][mx+k-(a[i][j]-b[i][j])]|=(f[i-1][j][mx+k]|f[i][j-1][mx+k]);
			}
		}
	int ans=0x3f3f3f3f;
	for(int k=-mx;k<=mx;k++) if(f[n][m][mx+k]) {
		ans=min(ans,abs(k));
	}
	cout<<ans;
	return 0;
}