#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define MAX (80 * 80 * 2 * 2)
#define BASE (MAX >> 1)
int main() {
	int h = ri(), w = ri();
	int a[h][w];
	for (auto &i : a) for (auto &j : i) j = ri();
	for (auto &i : a) for (auto &j : i) j -= ri();
	bool dp[h][w][MAX + 1];
	memset(dp, 0, sizeof(dp));
	dp[0][0][BASE + a[0][0]] = true;
	dp[0][0][BASE - a[0][0]] = true;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			for (int k = 0; k <= MAX; k++) {
				if (!dp[i][j][k]) continue;
				if (i + 1 < h) {
					dp[i + 1][j][k + a[i + 1][j]] = true;
					dp[i + 1][j][k - a[i + 1][j]] = true;
				}
				if (j + 1 < w) {
					dp[i][j + 1][k + a[i][j + 1]] = true;
					dp[i][j + 1][k - a[i][j + 1]] = true;
				}
			}
		}
	}
	int res = 1000000000;
	for (int i = 0; i <= MAX; i++) if (dp[h - 1][w - 1][i]) res = std::min(res, std::abs(i - BASE));
	std::cout << res << std::endl;
	return 0;
}
