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

using namespace std;

#define pb push_back

#define fi first

#define se second

#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define rep(i, n) for (int i = 0; i < (n); ++i)

#define repp(i, a, b) for (int i = a; i <= (b); ++i)

#define repr(i, a, b) for (int i = a; i >= (b); --i)

#define bit(n) (1LL << (n))

#define sz(x) ((ll)(x).size())

typedef long long ll;

const int INF = 1001001001;

const ll LINF = 1001001001001001001ll;

const int MOD = 1000000007;



template <class T>

inline bool chmin(T& a, T b) {

  if (a > b) {

    a = b;

    return true;

  }

  return false;

}



template <class T>

inline bool chmax(T& a, T b) {

  if (a < b) {

    a = b;

    return true;

  }

  return false;

}



int main() {

  int H, W;

  cin >> H >> W;

  vector<vector<int>> A(H, vector<int>(W));

  rep(i, H) {

    rep(j, W) {

      cin >> A[i][j];

    }

  }

  vector<vector<int>> B(H, vector<int>(W));

  rep(i, H) {

    rep(j, W) {

      cin >> B[i][j];

    }

  }



  vector<vector<int>> diff(H, vector<int>(W));

  rep(i, H) {

    rep(j, W) {

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

    }

  }



  int dpzero = 80 * 2 * (80 + 80);

  int dpmax = 80 * 4 * (80 + 80);

  vector<vector<vector<bool>>> dp(

      H, vector<vector<bool>>(W, vector<bool>(dpmax, false)));

  dp[0][0][dpzero + diff[0][0]] = true;

  dp[0][0][dpzero - diff[0][0]] = true;



  rep(i, H) {

    rep(j, W) {

      rep(k, dpmax) {

        if (dp[i][j][k] == false)

          continue;



        if (i + 1 < H) {

          dp[i + 1][j][k + diff[i + 1][j]] = true;

          dp[i + 1][j][k - diff[i + 1][j]] = true;

        }





        if (j + 1 < W) {

          dp[i][j + 1][k + diff[i][j + 1]] = true;

          dp[i][j + 1][k - diff[i][j + 1]] = true;

        }

      }

    }

  }



  int ans = INF;

  rep(k, dpmax) {

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

      continue;

    chmin(ans, abs(dpzero - k));

  }

  cout << ans << endl;

}

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

using namespace std;

#define MOD (long long int)(1e9+7)

#define ll long long int

#define rep(i,n) for(int i=0; i<(int)(n); i++)

#define reps(i,n) for(int i=1; i<=(int)(n); i++)

#define REP(i,n) for(int i=n-1; i>=0; i--)

#define REPS(i,n) for(int i=n; i>0; i--)

#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)

#define ALL(x) (x).begin(),(x).end()

#define RALL(a) (a).rbegin(), (a).rend()

#define CLR(a) memset((a), 0 ,sizeof(a))

#define PB push_back

#define MP make_pair

#define SP << " " <<

const int INF = 1001001001;

const ll LINF = 100100100100100100;

const double EPS = 1e-10;

const long double PI  = acos(-1.0L);

typedef pair<int,int> PII;

typedef vector<int> VI;

typedef vector<VI> VVI;

typedef vector<ll> VL;

#define chmax(a,b) a = (((a)<(b))?(b):(a))

#define chmin(a,b) a = (((a)>(b))?(b):(a))



__attribute__((constructor))

void initial(){

	cin.tie(nullptr);

	ios::sync_with_stdio(false);

	cout << fixed << setprecision(15);

}



signed main(){

	int h,w; cin>>h>>w;

	int a[h][w], b[h][w];

	const int max_k=(h+w)*80+5; //////

	rep(i,h) rep(j,w) cin>>a[i][j];

	rep(i,h) rep(j,w) cin>>b[i][j];

  vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(max_k,false))); //////

	// bool dp[h][w][max_k]; memset(dp,false,sizeof(dp));

	const int dh[2]={1,0}, dw[2]={0,1};

	dp[0][0][abs(a[0][0]-b[0][0])]=true;

	rep(now_h,h)rep(now_w,w){

		rep(i,2){

			int next_h=now_h+dh[i], next_w=now_w+dw[i];

			if(next_h>=h||next_w>=w) continue;

			int d=abs(a[next_h][next_w]-b[next_h][next_w]);

			rep(k,max_k){

				if(!dp[now_h][now_w][k]) continue;

				if(k+d<max_k) dp[next_h][next_w][k+d]=true;

				if(abs(k-d)<max_k) dp[next_h][next_w][abs(k-d)]=true;

			}

		}

	}

	int ans=max_k;

	rep(k,max_k){

		if(dp[h-1][w-1][k]) return cout<<k<<endl,0;

	}

	cout<<ans<<endl;

	return 0;

}