//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <deque>
#include <map>
using namespace std;

#define ii pair <int, int>
#define lli long long
#define pb push_back
#define X first
#define Y second

const int Mod = 1E9 + 7;
const int Inf = 1E9 + 7;
const int N = 80 + 10;
const int M = 80 * 160 + 1;

int n, m, a[N][N], b[N][N];
bool F[N][N][M][2];

void Input()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> b[i][j];
}

void Solve()
{
    memset(F, 0, sizeof(F));
    int Sum = a[1][1] - b[1][1];
    Sum = abs(Sum);
    F[1][1][Sum][1] = F[1][1][Sum][0] = true;


    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
    for (int k = 0; k < M; k++)
    for (int l = 0; l <= 1; l++){
        if (F[i][j][k][l] == true) {
            int sign = 1;
            if (l == 0) sign = -1;
            int k1 = k * sign + a[i + 1][j] - b[i + 1][j];
            int k2 = k * sign + a[i][j + 1] - b[i][j + 1];

            if (k1 >= 0) F[i + 1][j][k1][1] = true;
            else F[i + 1][j][-k1][0] = true;

            if (k2 >= 0) F[i][j + 1][k2][1] = true;
            else F[i][j + 1][-k2][0] = true;
            ///
            k1 = k * sign - a[i + 1][j] + b[i + 1][j];
            k2 = k * sign - a[i][j + 1] + b[i][j + 1];

            if (k1 >= 0) F[i + 1][j][k1][1] = true;
            else F[i + 1][j][-k1][0] = true;

            if (k2 >= 0) F[i][j + 1][k2][1] = true;
            else F[i][j + 1][-k2][0] = true;

        }
    }

    for (int k = 0; k < M; k++) if (F[n][m][k][0] == true || F[n][m][k][1] == true) {
        cout << k << " ";
        return ;
    }
}

#define task "test"
int main()
{
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int testcase = 1;
    /// cin >> testcase;
    while (testcase--) {
        Input();
        Solve();
    }
}



#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int H,W;
  cin >> H >> W;
  vector<vector<int>> A(H,vector<int>(W));
  rep(i,H){
    rep(j,W)  cin >> A.at(i).at(j);
  }
  vector<vector<int>> B(H,vector<int>(W));
  rep(i,H){
    rep(j,W)  cin >> B.at(i).at(j);
  }

  int base=100*(H+W);
  vector<vector<vector<bool>>> dp(H,vector<vector<bool>>(W,vector<bool>(2*base,false)));
  dp.at(0).at(0).at(base+A.at(0).at(0)-B.at(0).at(0))=true;
  dp.at(0).at(0).at(base-A.at(0).at(0)+B.at(0).at(0))=true;
  rep(i,H){
    rep(j,W){
      int tmp=A.at(i).at(j)-B.at(i).at(j);
      rep(k,2*base){
        if(i-1>=0 && dp.at(i-1).at(j).at(k)){
          if(k+tmp <2*base) dp.at(i).at(j).at(k+tmp)=true;
          if(k-tmp >=0) dp.at(i).at(j).at(k-tmp)=true;
        }
        if(j-1>=0 && dp.at(i).at(j-1).at(k)){
          if(k+tmp <2*base) dp.at(i).at(j).at(k+tmp)=true;
          if(k-tmp >=0) dp.at(i).at(j).at(k-tmp)=true;
        }
      }
    }
  }
  int ans=1e9;
  rep(i,2*base){
    if(!dp.at(H-1).at(W-1).at(i))  continue;
    chmin(ans,abs(i-base));
  }
  cout << ans << endl;

  return 0;
}