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

const int offset = 12800;
bitset<2 * offset + 1> dp[81][81];

int main() {
  int H, W; cin >> H >> W;
  vector<vector<int>> X(H + 1, vector<int>(W + 1, 0));
  rep(h, H) rep(w, W) cin >> X[h][w];
  rep(h, H) rep(w, W) {
    int B; cin >> B;
    X[h][w] -= B;
    if (X[h][w] < 0) X[h][w] = -X[h][w];
  }

  dp[0][0][offset + X[0][0]] = 1;

  rep(h, H) rep(w, W) {
    dp[h][w + 1] |= (dp[h][w] << X[h][w + 1]) | (dp[h][w] >> X[h][w + 1]);
    dp[h + 1][w] |= (dp[h][w] << X[h + 1][w]) | (dp[h][w] >> X[h + 1][w]);
  }

  const int INF = 1e9 + 10;
  int ans = INF;
  rep(i, 2 * offset + 1) {
    if (dp[H - 1][W - 1][i]) ans = min(ans, abs(i - offset));
  }

  cout << ans << endl;
}