/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int dp[82][82][13000 * 2 + 2] = {};

int main(){
  
  int h, w; cin >> h >> w;
  vector<vector<int>> a(h, vector<int> (w));
  vector<vector<int>> b(h, vector<int> (w));
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      cin >> b[i][j];
    }
  }
  
  int delta = 13000;
  dp[0][0][a[0][0] - b[0][0] + delta] = 1;
  dp[0][0][b[0][0] - a[0][0] + delta] = 1;

  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      for(int k = 0; k <= delta * 2; k++) {
        if(dp[i][j][k] == 0) continue;


        // 右
        if(j != w - 1) {
          int ni = i;
          int nj = j + 1;
          
          int nk1 = k + a[ni][nj] - b[ni][nj];
          if(0 <= nk1 and nk1 <= delta * 2) dp[ni][nj][nk1] = 1;

          int nk2 = k + b[ni][nj] - a[ni][nj];
          if(0 <= nk2 and nk2 <= delta * 2) dp[ni][nj][nk2] = 1;

        }

        // 下
        if(i != h - 1) {
          int ni = i + 1;
          int nj = j;
          
          int nk1 = k + a[ni][nj] - b[ni][nj];
          if(0 <= nk1 and nk1 <= delta * 2) dp[ni][nj][nk1] = 1;

          int nk2 = k + b[ni][nj] - a[ni][nj];
          if(0 <= nk2 and nk2 <= delta * 2) dp[ni][nj][nk2] = 1;

        }
      }
    }
  }

  lint ans = INF;
  for(int k = 0; k <= delta * 2; k++) {
    if(dp[h - 1][w - 1][k]) ans = min(ans, (lint)abs(k - delta));
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 666240