// Slower C++ solution:
#include<iostream>

#include<iomanip>

#include<vector>

#include<string>

#include<algorithm>

#include<cmath>

#include<functional>

#include<map>

#include<cstdlib>

#include<complex>

#include<numeric>

#include<set>

#include<deque>

#include<queue>



using namespace std;

using Int = long long;

Int INF = 1LL << 60;

const Int MOD = 1000000000 + 7;



template<class T>//ex) auto dp = make_vec(4,4,4,INF);

vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }

template<class... Size>

auto make_vec(size_t s, Size... tail) {

	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));

}



int main() {



	cin.tie(nullptr);

	ios::sync_with_stdio(false);



	Int H, W;

	cin >> H >> W;



	vector<vector<Int>> A(H+1, vector<Int>(W+1));

	vector<vector<Int>> B(H+1, vector<Int>(W+1));

	for (Int i = 0; i < H; i++) {

		for (Int j = 0; j < W; j++) {

			cin >> A[i][j];

		}

	}

	for (Int i = 0; i < H; i++) {

		for (Int j = 0; j < W; j++) {

			cin >> B[i][j];

		}

	}



	auto dp = make_vec(H+1, W+1, 13000, 0);

	dp[0][0][abs(A[0][0]-B[0][0])] = 1;



	

	for (Int i = 0; i < H; i++) {

		for (Int j = 0; j < W; j++) {

			for (Int k = 0; k < 13000; k++) {

				if (dp[i][j][k]) {

					dp[i + 1][j][k + abs(A[i + 1][j] - B[i + 1][j])] = 1;

					dp[i + 1][j][abs(k - abs(A[i + 1][j] - B[i + 1][j]))] = 1;//kが負になる場合は正に切り返す



					dp[i][j + 1][k + abs(A[i][j + 1] - B[i][j + 1])] = 1;

					dp[i][j + 1][abs(k - abs(A[i][j + 1] - B[i][j + 1]))] = 1;//kが負になる場合は正に切り返す



				}

			}

		}

	}



	Int ans;

	for (Int k = 0; k < 13000; k++) {

		if (dp[H-1][W-1][k]) {

			cout << k << "\n";

			return 0;

		}

	}



}


// Faster C++ solution for the same problem (measured speedup: 2.0882356831708155x):
#include<iostream>

#include<iomanip>

#include<vector>

#include<string>

#include<algorithm>

#include<cmath>

#include<functional>

#include<map>

#include<cstdlib>

#include<complex>

#include<numeric>

#include<set>

#include<deque>

#include<queue>



using namespace std;

using Int = long long;

Int INF = 1LL << 60;

const Int MOD = 1000000000 + 7;



template<class T>//ex) auto dp = make_vec(4,4,4,INF);

vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }

template<class... Size>

auto make_vec(size_t s, Size... tail) {

	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));

}



int main() {



	cin.tie(nullptr);

	ios::sync_with_stdio(false);



	Int H, W;

	cin >> H >> W;



	vector<vector<Int>> A(H+1, vector<Int>(W+1));

	vector<vector<Int>> B(H+1, vector<Int>(W+1));

	for (Int i = 0; i < H; i++) {

		for (Int j = 0; j < W; j++) {

			cin >> A[i][j];

		}

	}

	for (Int i = 0; i < H; i++) {

		for (Int j = 0; j < W; j++) {

			cin >> B[i][j];

		}

	}



	auto dp = make_vec(H+1, W+1, 13000, false);

	dp[0][0][abs(A[0][0]-B[0][0])] = true;



	

	for (Int i = 0; i < H; i++) {

		for (Int j = 0; j < W; j++) {

			for (Int k = 0; k < 13000; k++) {

				if (dp[i][j][k]) {

					dp[i + 1][j][k + abs(A[i + 1][j] - B[i + 1][j])] =true;

					dp[i + 1][j][abs(k - abs(A[i + 1][j] - B[i + 1][j]))] = true;//kが負になる場合は正に切り返す



					dp[i][j + 1][k + abs(A[i][j + 1] - B[i][j + 1])] = true;

					dp[i][j + 1][abs(k - abs(A[i][j + 1] - B[i][j + 1]))] = true;//kが負になる場合は正に切り返す



				}

			}

		}

	}



	Int ans;

	for (Int k = 0; k < 13000; k++) {

		if (dp[H-1][W-1][k]) {

			cout << k << "\n";

			return 0;

		}

	}



}