#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int BASE = 80 * 160 + 5;
int A[85][85];
bool dp[85][85][BASE*2];

int main() {
    int h, w;
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> A[i][j];
    rep(i, h) rep(j, w) {
      int a;
      cin >> a;
      A[i][j] -= a;
    }
    dp[0][0][BASE+A[0][0]] = dp[0][0][BASE-A[0][0]] = true;
    rep(i, h) rep(j, w) rep(k, BASE*2) {
      int x = k - A[i][j], y = k + A[i][j];
      if (0<=x && x<BASE*2) {
        if (i) dp[i][j][k] |= dp[i-1][j][x];
        if (j) dp[i][j][k] |= dp[i][j-1][x];
      }
      if (0<=y && y<BASE*2) {
        if (i) dp[i][j][k] |= dp[i-1][j][y];
        if (j) dp[i][j][k] |= dp[i][j-1][y];
      }
    }
    int ans = BASE*2;
    rep(i, BASE*2) {
      if (dp[h-1][w-1][i]) ans = min(ans, abs(i-BASE));
    }
    cout << ans << endl;
    return 0;
}