#include <bits/stdc++.h>
using namespace std;
#define inf (int)(1e9)
const int M = 80 * 160;

int main(){
	int H, W, i, j;
	scanf("%d%d", &H, &W);
	vector<vector<int>> A(H, vector<int>(W));
	for(i = 0; i < H; i++){
		for(j = 0; j < W; j++){
			scanf("%d", &A[i][j]);
		}
	}
	for(i = 0; i < H; i++){
		for(j = 0; j < W; j++){
			int B;
			scanf("%d", &B);
			A[i][j] = abs(A[i][j] - B);
		}
	}
	vector<vector<bitset<2 * M>>> dp(H, vector<bitset<2 * M>>(W, bitset<2 * M>(0)));
	dp[0][0][M + A[0][0]] = 1;
	dp[0][0][M - A[0][0]] = 1;
	for(i = 0; i < H; i++){
		for(j = 0; j < W; j++){
			if(i > 0){
				dp[i][j] |= (dp[i - 1][j] << A[i][j]);
				dp[i][j] |= (dp[i - 1][j] >> A[i][j]);
			}
			if(j > 0){
				dp[i][j] |= (dp[i][j - 1] << A[i][j]);
				dp[i][j] |= (dp[i][j - 1] >> A[i][j]);
			}
		}
	}
	int ans = inf;
	for(i = 0; i < 2 * M; i++){
		if(dp[H - 1][W - 1][i] == 1){
			ans = min(ans, abs(i - M));
		}
	}
	printf("%d\n", ans);
	return 0;
}