#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
// define
constexpr int INF = 1 << 24;
#define endl "\n"
#ifdef LOCAL
#define lout cerr
#else
ostream devnull(0);
#define lout devnull
#endif
// rep
// Inspired by:
// https://github.com/kurokoji/.cpp-Template/blob/master/template/template2.cpp
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...)                                 \
  GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1) \
  (__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, d) rep5(i, a, n, d, <)
#define rep5(i, a, n, d, o) \
  for (auto i = decltype(n)(a), i##_len = (n); i o i##_len; i += (d))

#define rrep(...)                                    \
  GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1) \
  (__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, -1)
#define rrep4(i, a, n, d) rep5(i, (a)-1, n, d, >=)

#define repc(...)                                    \
  GET_MACRO(__VA_ARGS__, repc4, repc3, repc2, repc1) \
  (__VA_ARGS__)
#define repc1(n) repc2(_, n)
#define repc2(i, n) repc3(i, 0, n)
#define repc3(i, a, n) repc4(i, a, n, 1)
#define repc4(i, a, n, d) rep5(i, a, n, d, <=)
// alias
typedef long long ll;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
// func
template <class C>
void vcin(C &c)
{
  for (auto &&a : c)
  {
    cin >> a;
  }
}
template <class C, class D>
void vcin(C &c, D &d)
{
  for (auto it1 = c.begin(), it2 = d.begin(); it1 != c.end() && it2 != d.end();
       it1++, it2++)
  {
    cin >> *it1 >> *it2;
  }
}
template <class C>
void vcout(const C &c, const string delimiter)
{
  for (auto it = c.begin(); it != c.end(); it++)
  {
    if (it != c.begin())
      cout << delimiter;
    cout << *it;
  }
}
template <class T = int>
inline T input()
{
  T x;
  cin >> x;
  return (x);
}
template <typename T>
inline void chmax(T &x, const T y)
{
  if (x < y)
    x = y;
}
template <typename T>
inline void chmin(T &x, const T y)
{
  if (x > y)
    x = y;
}
#define CPPV __cplusplus / 100 % 100 //C++ Version
#if 1

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v)
{
  t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v)
{
  for (auto &e : t)
    fill_v(e, v);
}
#endif

#define dump(x) lout << #x << " = " << (x) << endl;
//#define bit(n) (1LL << (n))
inline lint bit(lint n) { return 1LL << n; }

void solve()
{
  int h, w;
  cin >> h >> w;
  auto a = make_v<int>(h, w);
  auto b = make_v<int>(h, w);

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

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

  auto d = make_v<int>(h, w);
  rep(i, h) rep(j, w)
  {
    d[i][j] = a[i][j] - b[i][j];
  }

#ifdef LOCAL
  rep(i, h)
  {
    rep(j, w)
    {
      lout << a[i][j] << "," << b[i][j] << "\t";
    }
    lout << endl;
  }
  lout << endl;
  rep(i, h)
  {
    rep(j, w)
    {
      lout << d[i][j] << "\t";
    }
    lout << endl;
  }

#endif

  constexpr int K_MAX = 80 * 80 * 2 + 1;

  auto dp = make_v<int>(h, w, K_MAX);
  fill_v(dp, 0);

  dp[0][0][abs(d[0][0])] = 1;
  dump(__LINE__);

#define ifisvalid(n) if (0 <= (n) && (n) < K_MAX)
#define update(i_next, j_next, k_next) ifisvalid(k_next) chmax(dp[i_next][j_next][k_next], dp[i][j][k]);

  rep(i, h)
      rep(j, w)
          rep(k, K_MAX)
  {
    if (i + 1 < h)
    {
      update(i + 1, j, k + d[i + 1][j]);
      update(i + 1, j, k - d[i + 1][j]);
      update(i + 1, j, -k + d[i + 1][j]);
      update(i + 1, j, -k - d[i + 1][j]);
    }
    if (j + 1 < w)
    {
      update(i, j + 1, k + d[i][j + 1]);
      update(i, j + 1, k - d[i][j + 1]);
      update(i, j + 1, -k + d[i][j + 1]);
      update(i, j + 1, -k - d[i][j + 1]);
    }
  }
  dump(__LINE__);

  // rep(i,h)
  //     rep(j,w)
  //         rep(k, K_MAX) if (k < 3)
  // {
  //   lout << i << j << k << " " << dp[i][j][k] << endl;
  // }

  rep(k, K_MAX)
  {
    if (dp[h - 1][w - 1][k])
    {
      cout << k << endl;
      return;
    }
  }
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  solve();

  return 0;
}


Measured memory_bytes: 324608