// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define P pair<ll,ll>

#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)

#define TO(x,t,f) ((x)?(t):(f))

#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9

#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted

#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted

#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted

#define REV(x) (reverse(x.begin(),x.end())) //reverse

ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}

ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}

#define NEXTP(x) next_permutation(x.begin(),x.end())

const ll INF=ll(1e18)+ll(7);

const ll MOD=1000000007LL;

#define out(a) cout<<fixed<<setprecision((a))



int H,W;

int A[82][82];

int B[82][82];

int C[82][82];// +C or -C

bool D[82][82][6402*2]={};// p



int main(){

	cin >> H >> W;

	FOR(i,0,H)FOR(j,0,W){

		cin >> A[i][j];

	}

	FOR(i,0,H)FOR(j,0,W){

		cin >> B[i][j];

		C[i][j] = abs(A[i][j]-B[i][j]);

	}

	D[0][0][C[0][0]]=1;

	vector<int> X[82][82];

	X[0][0].push_back(C[0][0]);



	FOR(i,0,H){

		FOR(j,0,W){// 確定していく

			if(i>0){

				for(auto x:X[i-1][j]){

					int a[4];

					a[0] = x - C[i][j];

					a[1] = x + C[i][j];

					a[2] = C[i][j] - x;

					a[3] = C[i][j] + x;

					FOR(k,0,4){

						if( a[k]>=0 && not D[i][j][abs(a[k])]){

							D[i][j][a[k]]=true;

							X[i][j].push_back(a[k]);

						}

					}

				}

			}

			if(j>0){

				for(auto x:X[i][j-1]){

					int a[4];

					a[0] = x - C[i][j];

					a[1] = x + C[i][j];

					a[2] = C[i][j] - x;

					a[3] = C[i][j] + x;

					FOR(k,0,4){

						if( a[k]>=0 && not D[i][j][abs(a[k])]){

							D[i][j][a[k]]=true;

							X[i][j].push_back(a[k]);

						}

					}

				}

			}

		}

	}

	int ans = X[H-1][W-1][0];

	for(auto x:X[H-1][W-1]){

		ans = min(ans,x);

	}

	cout << ans << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1733919133541282x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define P pair<ll,ll>

#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)

#define TO(x,t,f) ((x)?(t):(f))

#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9

#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted

#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted

#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted

#define REV(x) (reverse(x.begin(),x.end())) //reverse

ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}

ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}

#define NEXTP(x) next_permutation(x.begin(),x.end())

const ll INF=ll(1e18)+ll(7);

const ll MOD=1000000007LL;

#define out(a) cout<<fixed<<setprecision((a))



int H,W;

int A[82][82];

int B[82][82];

int C[82][82];// +C or -C

bool D[82][82][6402*2]={};// p



int main(){

	cin >> H >> W;

	FOR(i,0,H)FOR(j,0,W){

		cin >> A[i][j];

	}

	FOR(i,0,H)FOR(j,0,W){

		cin >> B[i][j];

		C[i][j] = abs(A[i][j]-B[i][j]);

	}

	D[0][0][C[0][0]]=1;



	FOR(i,0,H){

		FOR(j,0,W){// 確定していく

			if(i>0){

				FOR(k,0,80*(i+j+2)+1){

					if(not D[i-1][j][k])continue;

					int a[2];

					a[0] = abs( k - C[i][j] );

					a[1] = abs( k + C[i][j] );

					FOR(l,0,2){

						if( a[l]>=0 && not D[i][j][a[l]]){

							D[i][j][a[l]]=true;

						}

					}

				}

			}

			if(j>0){

				FOR(k,0,80*(i+j+2)+1){

					if(not D[i][j-1][k])continue;

					int a[2];

					a[0] = abs( k - C[i][j] );

					a[1] = abs( k + C[i][j] );

					FOR(l,0,2){

						if( a[l]>=0 && not D[i][j][a[l]]){

							D[i][j][a[l]]=true;

						}

					}

				}

			}

		}

	}

	FOR(i,0,80*(H+W)+1){

		if(D[H-1][W-1][i]){

			cout << i << endl;

			return 0;

		}

	}

}