#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<iostream>
#define ll long long
using namespace std;
const int N = 81;
const int  av=12800;
int h,w,ans,a[N][N],b[N][N],x[N][N];
bool can[N][N][N*N*4+160];
int main(){
	scanf("%d%d",&h,&w);
	ans=0x7fffffff;
	for(int i=1;i<=h;i++) 
		for(int j=1;j<=w;j++) 	
			scanf("%d",&a[i][j]);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++) 	
			scanf("%d",&b[i][j]);
	can[0][1][av]=1;can[1][0][av]=1;
	for(int i=1;i<=h;i++) 
		for(int j=1;j<=w;j++){
			x[i][j]=max(a[i][j],b[i][j])+max(x[i-1][j],x[i][j-1]);
			int k1=a[i][j]-b[i][j];
			int k2=-k1;
			for(int k=x[i][j]+av;k>=av-x[i][j];k--) 
				if(can[i-1][j][k-k1]||can[i-1][j][k-k2]||can[i][j-1][k-k1]||can[i][j-1][k-k2])
					can[i][j][k]=1;
		}
	for(int k=av-x[h][w];k<=av+x[h][w];k++)
		if(can[h][w][k]) 
			ans=min(ans,abs(k-av)); 
	printf("%d\n",ans);
	return 0;
}
