#include <bits/stdc++.h>
using namespace std;
using ll = long long;
class in {
  int n;

 public:
  in() {}
  in(int n_) : n(n_){};
  template <class T>
  operator T() {
    T ret;
    cin >> ret;
    return ret;
  }
  template <class T>
  operator vector<T>() {
    vector<T> ret(n);
    for (int i = 0; i < n; i++) cin >> ret[i];
    return ret;
  }
};
template <std::uint_fast64_t Mod>
class modint {
  using u64 = std::uint_fast64_t;
  u64 a;

 public:
  constexpr modint(const u64 x = 0) noexcept : a(x % Mod) {}
  constexpr u64 val() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr bool operator==(const modint rhs) const noexcept {
    return modint(*this).val() == rhs.val();
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Mod) a -= Mod;
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) a += Mod;
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Mod;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Mod - 2;
    while (exp) {
      if (exp % 2) *this *= rhs;
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
template <std::uint_fast64_t Mod>
ostream &operator<<(ostream &os, const modint<Mod> &m) {
  return os << m.a;
}
const ll mod = (ll)1e9 + 7;
using mint = modint<mod>;
int A[80][80];
int s[80][80][6400];
struct Pos {
  int x;
  int y;
};
int main() {
  int H = in();
  int W = in();
  for (int h = (int)(0), h_end = (int)(H); h < h_end; ++h)
    for (int w = (int)(0), w_end = (int)(W); w < w_end; ++w) A[h][w] = in();
  for (int h = (int)(0), h_end = (int)(H); h < h_end; ++h)
    for (int w = (int)(0), w_end = (int)(W); w < w_end; ++w) {
      int B = in();
      A[h][w] -= B;
      if (A[h][w] < 0) A[h][w] *= -1;
    }
  s[0][0][A[0][0]] = 1;
  const int kMax = 6400;
  for (int y = (int)(0), y_end = (int)(H); y < y_end; ++y)
    for (int x = (int)(0), x_end = (int)(W); x < x_end; ++x) {
      if (x != W - 1) {
        for (int v = (int)(0), v_end = (int)(kMax); v < v_end; ++v) {
          if (!s[y][x][v]) continue;
          s[y][x + 1][v + A[y][x + 1]] = 1;
          s[y][x + 1][abs(v - A[y][x + 1])] = 1;
        }
      }
      if (y != H - 1) {
        for (int v = (int)(0), v_end = (int)(kMax); v < v_end; ++v) {
          if (!s[y][x][v]) continue;
          s[y + 1][x][v + A[y + 1][x]] = 1;
          s[y + 1][x][abs(v - A[y + 1][x])] = 1;
        }
      }
    }
  int ans = 1000000;
  for (int v = (int)(0), v_end = (int)(kMax); v < v_end; ++v) {
    if (!s[H - 1][W - 1][v]) continue;
    ans = min(ans, v);
  }
  cout << ans << endl;
  return 0;
}
