#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
小数の桁数を指定する
	cout << setprecision(8)<< mp[0]-mx << endl;
*/

ll m[128][128][13000] = {0};
int main()
{
	ll i,j,k,a,b,ans=0;
	char c;
	ll N,M,T, X,Y;
	ll mp[128][128] = {0};
	queue<pair<ll,ll> > q;
	cin >> N >> M;
	for(i=0;i<N;++i)
	{
		for(j=0;j<M;++j)
		{
			cin >> mp[j][i];
		}
	}
	for(i=0;i<N;++i)
	{
		for(j=0;j<M;++j)
		{
			cin >> k;
			mp[j][i] -= k;
			mp[j][i] = ABS(mp[j][i]);
		}
	}
	/*
	for(i=0;i<N;++i)
	{
		for(j=0;j<M;++j)
		{
			cout << mp[j][i] << " ";
		}
		cout << endl;
	}*/
	q.push(make_pair(0,0));
	int pos, num, nx;
	while(!q.empty())
	{
		pos = q.front().first;
		num = q.front().second;
		q.pop();
		X = pos%100;
		Y = pos/100;
		nx = num + mp[X][Y];
		//cout << X << " " << Y << " " << num << endl;
		if(X < M-1 && m[X+1][Y][nx] == 0)
		{
			m[X+1][Y][nx] = 1;
			q.push(make_pair(pos+1, nx));
		}
		if(Y < N-1 && m[X][Y+1][nx] == 0)
		{
			m[X][Y+1][nx] = 1;
			q.push(make_pair(pos+100, nx));
		}
		nx = ABS(num - mp[X][Y]);
		if(X < M-1 && m[X+1][Y][nx] == 0)
		{
			m[X+1][Y][nx] = 1;
			q.push(make_pair(pos+1, nx));
		}
		if(Y < N-1 && m[X][Y+1][nx] == 0)
		{
			m[X][Y+1][nx] = 1;
			q.push(make_pair(pos+100, nx));
		}
	}
	for(i=0;i<13000;++i)
	{
		if(m[M-1][N-1][i])
		{
			m[M][N][i + mp[M-1][N-1]] = 1;
			m[M][N][ABS(i - mp[M-1][N-1])] = 1;
		}
	}
	for(i=0;i<13000;++i)
	{
		if(m[M][N][i])
		{
			cout << i << endl;
			break;
		}
	}
	return 0;
}




















Measured memory_bytes: 810932