#include<bits/stdc++.h>
#define ll long long
#define R register
using namespace std;
const int N =82;
template <class Ruby_Rose> inline void read(Ruby_Rose &x)
{
 	x=0;
	char ch=getchar(), w=0;
	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
	x=w?-x:x;
}
int n, m, val[N][N], f[N][N][N*N*4], ans=2e9;

int main()
{
	read(n), read(m);
	for(R int i=1; i<=n; i++)
		for(R int j=1; j<=m; j++)
			read(val[i][j]);
	for(R int i=1; i<=n; i++)
		for(R int j=1, qa; j<=m; j++)
			read(qa), val[i][j]-=qa;
	f[1][1][N*N*2+val[1][1]]=1;
	for(R int i=1; i<=n; i++)
	{
		for(R int j=1; j<=m; j++)
		{
			for(R int k=1; k<N*N*4; k++)
			{
				f[i+1][j][k+val[i+1][j]]|=f[i][j][k];
				f[i][j+1][k+val[i][j+1]]|=f[i][j][k];
				f[i+1][j][k-val[i+1][j]]|=f[i][j][k];
				f[i][j+1][k-val[i][j+1]]|=f[i][j][k];
			}
		}
	}
	for(R int k=1; k<N*N*4; k++)
		if(f[n][m][k])ans=min(ans, abs(N*N*2-k));
	cout<<ans<<endl;
	return 0;
}