#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

constexpr int MAX = 160 * 80 + 1;
bool dp[81][81][MAX];

int a[80][80], b[80][80], c[80][80];

int main() {
  int h, w;
  cin >> h >> w;
  rep(i, 0, h) rep(j, 0, w) cin >> a[i][j];
  rep(i, 0, h) rep(j, 0, w) cin >> b[i][j];
  rep(i, 0, h) rep(j, 0, w) c[i][j] = abs(a[i][j] - b[i][j]);

  dp[0][0][c[0][0]] = true;
  rep(i, 0, h) rep(j, 0, w) rep(k, 0, MAX) {
    if (i) {
      dp[i][j][k + c[i][j]] |= dp[i - 1][j][k];
      dp[i][j][abs(k - c[i][j])] |= dp[i - 1][j][k];
    }
    if (j) {
      dp[i][j][k + c[i][j]] |= dp[i][j - 1][k];
      dp[i][j][abs(k - c[i][j])] |= dp[i][j - 1][k];
    }
  }

  rep(i, 0, MAX) if (dp[h - 1][w - 1][i]) {
    cout << i << endl;
    return 0;
  }
}