#include <bits/stdc++.h>
using namespace std;

bool can[81][81][12801];
int a[81][81], b[81][81];

signed main () {
	int h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j)
			cin >> a[i][j];
	}
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j)
			cin >> b[i][j];
	}
	can[1][1][abs(a[1][1] - b[1][1])] = 1;
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			for (int k = 0; k <= 12800; ++k) {
				if (can[i][j][k]) {
					if (i != h) {
						can[i + 1][j][k + abs(a[i + 1][j] - b[i + 1][j])] = 1;
						can[i + 1][j][abs(k - abs(a[i + 1][j] - b[i + 1][j]))] = 1;
					}
					if (j != w) {
						can[i][j + 1][k + abs(a[i][j + 1] - b[i][j + 1])] = 1;
						can[i][j + 1][abs(k - abs(a[i][j + 1] - b[i][j + 1]))] = 1;
					}
				}
			}
		}
	}
	for (int k = 0; k <= 80; ++k) {
		if (can[h][w][k]) {
			cout << k << '\n';
			return 0;
		}
	}
}
