// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <string.h>

#include <vector>

#include <queue>

#include <cmath>

#include <bitset>

#include <complex>

#include <functional>

#include <numeric>

#include <iomanip>



// output

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');

#define YES cout << "YES" << endl

#define Yes cout << "Yes" << endl

#define NO cout << "NO" << endl

#define No cout << "No" << endl

// utility

#define ALL(i) (i).begin(), (i).end()

#define FOR(i, a, n) for(int i=(a);i<(n);++i)

#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)

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

#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)

#define IN(a, x, b) (a<=x && x<b)

#define OUT(a, x, b) (x<a || b<=x)

template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }

template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }



// type/const

#define int ll

using ll = long long;

using ull = unsigned long long;

using ld = long double;

const int MOD = 1000000007;

/* const int MOD = 998244353; */

const int INF = 1e18;

const double PI = acos(-1);



using namespace std;

struct INIT { INIT(){

  cin.tie(0); ios::sync_with_stdio(false);

  cout << fixed << setprecision(10);

}}INIT;





signed main() {

  int H, W; 

  cin >> H >> W;



  vector<vector<int>> A(H, vector<int>(W));

  REP(i, H) REP(j, W) cin >> A[i][j];



  vector<vector<int>> B(H, vector<int>(W));

  REP(i, H) REP(j, W) cin >> B[i][j];



  bool dp[H+1][W+1][40000];

  memset(dp, false, sizeof(dp));

  dp[0][0][20000] = true;

  

  REP(i, H) REP(j, W) REP(k, 40000){

    if(!dp[i][j][k]) continue;

    dp[i+1][j][k+A[i][j]-B[i][j]] = true;

    dp[i+1][j][k-A[i][j]+B[i][j]] = true;

    dp[i][j+1][k+A[i][j]-B[i][j]] = true;

    dp[i][j+1][k-A[i][j]+B[i][j]] = true;

  }



  int ans = INF;

  REP(k, 40000){

    if(dp[H-1][W][k]) chmin(ans, abs(20000-k));

    if(dp[H][W-1][k]) chmin(ans, abs(20000-k));

  }



  cout << ans << "\n";



  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.428089229951873x):
#include <iostream>

#include <algorithm>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <string.h>

#include <vector>

#include <queue>

#include <cmath>

#include <bitset>

#include <complex>

#include <functional>

#include <numeric>

#include <iomanip>



#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');

#define YES cout << "YES" << endl

#define Yes cout << "Yes" << endl

#define NO cout << "NO" << endl

#define No cout << "No" << endl

#define ALL(i) (i).begin(), (i).end()

#define FOR(i, a, n) for(int i=(a);i<(n);++i)

#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)

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

#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)

#define IN(a, x, b) (a<=x && x<b)

#define OUT(a, x, b) (x<a || b<=x)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



#define int ll

using ll = long long;

using ull = unsigned long long;

using ld = long double;

const int MOD = 1000000007;

/* const int MOD = 998244353; */

const int INF = 1e18;

const double PI = acos(-1);



using namespace std;

struct INIT { INIT(){

  cin.tie(0); ios::sync_with_stdio(false);

  cout << fixed << setprecision(10);

}}INIT;





signed main() {

  int H, W;

  cin >> H >> W;



  vector<vector<int>> A(H, vector<int>(W));

  REP(i, H) REP(j, W) cin >> A[i][j];



  REP(i, H) REP(j, W){

    int B;

    cin >> B;

    A[i][j] -= B;

  }





  const int MAX = 10000;

  vector<vector<vector<bool>>> dp(H+1, vector<vector<bool>>(W+1, vector<bool>(MAX, false)));

  dp[0][0][0] = true;



  auto f = [&](int i, int j, int x){

    x = abs(x);

    if(x >= MAX) return;

    dp[i+1][j][x] = true;

    dp[i][j+1][x] = true;

  };



  REP(i, H) REP(j, W) REP(k, MAX){

    if(dp[i][j][k]){

      f(i, j, k-A[i][j]);

      f(i, j, k+A[i][j]);

    }

  }



  REP(k, MAX){

    if(dp[H-1][W][k] || dp[H][W-1][k]){

      cout << k << "\n";

      return 0;

    }

  }



  return 0;

}