#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxV = 90010;
const int maxN = 88;
const int inf = 0x3f3f3f3f;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000010LL;
#define X first
#define Y second

int a[maxN][maxN];
int b[maxN][maxN];
int n,m;
bitset<26000> f[maxN][maxN];
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[0][1].set(13000);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			int y = abs(a[i][j] - b[i][j]);
			auto tmp = f[i-1][j] | f[i][j-1];
			f[i][j] = ((tmp<<y) | (tmp >> y));
		}
	}
	int ans = inf;
	for(int i=0;i<26000;i++)
	{
		if(f[n][m][i])
		{
			ans = min(abs(i-13000),ans);
		}
	}
	cout<<ans<<endl;
	return 0;
}