#include <bits/stdc++.h>
using namespace std;
const int MAXN=82;
bool dp[MAXN][MAXN][MAXN*MAXN*2];
int n,m,a[MAXN][MAXN],b[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]);}
	}
	dp[1][1][abs(a[1][1]-b[1][1])]=1;
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=m;j++) {
			for (int k=0;k<=80*(i+j);k++) {
				dp[i+1][j][abs(k+a[i+1][j]-b[i+1][j])]|=dp[i][j][k];
				dp[i+1][j][abs(k+b[i+1][j]-a[i+1][j])]|=dp[i][j][k];
				dp[i][j+1][abs(k+a[i][j+1]-b[i][j+1])]|=dp[i][j][k];
				dp[i][j+1][abs(k+b[i][j+1]-a[i][j+1])]|=dp[i][j][k];
			}
		}
	}
	for (int i=0;i<=80*80*2;i++) {
		if (dp[n][m][i]) {
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}