#include <bits/stdc++.h>

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

bool dp[90][90][13600];

signed main(){

	lli h,w;
	cin>>h>>w;

	lli a[100][100];
	lli b[100][100];
	lli data[100][100];

	REP(i,0,h)REP(j,0,w)cin>>a[i][j];
	REP(i,0,h)REP(j,0,w)cin>>b[i][j];

	REP(i,0,h)REP(j,0,w)data[i][j] = abs(a[i][j]-b[i][j]);

	dp[0][0][data[0][0]]=true;
	REP(i,0,h){
		REP(j,0,w){
			REP(k,0,13600){
				if(dp[i][j][k]){
					dp[i+1][j][abs(k+data[i+1][j])] = true;
					dp[i+1][j][abs(k-data[i+1][j])] = true;
					dp[i][j+1][abs(k+data[i][j+1])] = true;
					dp[i][j+1][abs(k-data[i][j+1])] = true;
				}
			}
		}
	}

	REP(i,0,13600){
		if(dp[h-1][w-1][i]){
			cout<<i<<endl;
			break;
		}
	}

	return 0;
}