#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;


void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//幅優先探索のテンプレ.デフォルトではstartからの距離を返す.
//graphは隣接リスト.startは探索開始地点
vector<int> bfs(vector<vector<int>> &graph, int start){
	queue<int> todo;
	vector<int> dist(graph.size(),-1);
	dist[start] = 0;
	todo.push(start);
	while(!todo.empty()){
		int now = todo.front();
		todo.pop();
		for (int i=0;i<graph[now].size();i++){
			int nxt = graph[now][i];
			if (dist[nxt] != -1) continue;
			dist[nxt] = dist[now] + 1;
			todo.push(nxt);
		}
	}
	return dist;
}

const int D = 80*160+10;
const int D2 = D*2;
typedef bitset<D2> bs;
 
int a[100][100];
bs dp[90][90];
 
int main() {
  int h, w;
  cin >> h >> w;
  rep(i,h)rep(j,w) {
    int x;
    cin >> x;
    a[i][j] = x;
  }
  rep(i,h)rep(j,w) {
    int x;
    cin >> x;
    a[i][j] = abs(x-a[i][j]);
  }
 
  dp[0][0][D-a[0][0]] = 1;
  dp[0][0][D+a[0][0]] = 1;
  rep(i,h)rep(j,w) {
    if (i) {
      dp[i][j] |= dp[i-1][j]<<a[i][j];
      dp[i][j] |= dp[i-1][j]>>a[i][j];
    }
    if (j) {
      dp[i][j] |= dp[i][j-1]<<a[i][j];
      dp[i][j] |= dp[i][j-1]>>a[i][j];
    }
  }
  int ans = D2;
  rep(i,D2) if (dp[h-1][w-1][i]) {
    ans = min(ans, abs(i-D));
  }
  cout << ans << endl;
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int H,W;cin>>H>>W;
	int A[H][W] = {}; int a;
	rep(i,0,H)rep(j,0,W){ cin>>a; A[i][j] += a; }
	rep(i,0,H)rep(j,0,W){ cin>>a; A[i][j] -= a; }
	bool dp[H+1][W+1][12801] = {}; dp[0][1][0] = 1;
	rep(i,1,H+1)rep(j,1,W+1){
        int t = abs(A[i-1][j-1]);
		rep(k,0,12801){
			if(k + t <= 12800) dp[i][j][k+t] |= dp[i-1][j][k] | dp[i][j-1][k];
            dp[i][j][abs(k - t)] |= dp[i-1][j][k] | dp[i][j-1][k];
		}
	}
	rep(i,0,12801){
		if(dp[H][W][i]){
            cout<<i<<endl;
            break;
        }
	}
}