#include <bits/stdc++.h>

using namespace std;

int n, m;
int a[101][101], b[101][101];
bitset<20001> f[101][101];

int main(int argc, char** argv)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> b[i][j];
	f[1][1].set(10000);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			int v1 = a[i][j] - b[i][j];
			int v2 = b[i][j] - a[i][j];
			if (v1 >= 0)
			{
				f[i + 1][j] |= (f[i][j] << v1);
				f[i][j + 1] |= (f[i][j] << v1); 
			}	
			else
			{
				v1 = -v1;
				f[i + 1][j] |= (f[i][j] >> v1);
				f[i][j + 1] |= (f[i][j] >> v1); 
			}	
			if (v2 >= 0)
			{
				f[i + 1][j] |= (f[i][j] << v2);
				f[i][j + 1] |= (f[i][j] << v2);
			}
			else
			{
				v2 = -v2;
				f[i + 1][j] |= (f[i][j] >> v2);
				f[i][j + 1] |= (f[i][j] >> v2);
			}	
		}
	int ans = 1e9;
	for (int i = 0; i <= 20000; i++)
		if (f[n][m].test(i))
		{       
			int v1 = i + a[n][m] - b[n][m];
			int v2 = i + b[n][m] - a[n][m];
			ans = min(ans, min(abs(v1 - 10000), abs(v2 - 10000)));
		} 
	cout << ans;	
}
#include<bits/stdc++.h>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 88
#define MAXS 13000

int dp[MAXN][MAXN][MAXS];

int main(){
  int h,w;cin>>h>>w;
  vector<vector<int>> scores(h);
  rep(i, h)rep(j, w){
    int a;cin>>a;
    scores[i].push_back(a);
  }
  rep(i, h)rep(j, w){
    int a;cin>>a;
    scores[i][j] -= a;
    if(scores[i][j] < 0)scores[i][j] *= -1;
  }

  dp[0][0][scores[0][0]] = 1;
  rep(i, h)rep(j, w)rep(k, MAXS){
    int s = scores[i][j];
    int mpre = k-s;
    if(mpre<0)mpre *= -1;
    if(i && dp[i-1][j][mpre]==1)dp[i][j][k]=1;
    if(j && dp[i][j-1][mpre]==1)dp[i][j][k]=1;

    int ppre = k+s;
    if(ppre<=7000){
      if(i && dp[i-1][j][ppre]==1)dp[i][j][k]=1;
      if(j && dp[i][j-1][ppre]==1)dp[i][j][k]=1;
    }
  }

  int result = 0;
  rrep(i, MAXS)if(dp[h-1][w-1][i])result = i;

  cout<<result<<endl;

  return 0;

  rep(i, h){
    rep(j, w)cout<<scores[i][j]<<' ';cout<<endl;
  }
cout<<"###"<<endl;

rep(k, 15){
cout<<k<<endl;
  rep(i, h){
    rep(j, w)cout<<dp[i][j][k]<<' ';cout<<endl;
  }
  cout<<"---"<<endl;
}

  return 0;
}
