#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const long long INF = 1e17;

int main() {
  ll H,W;
  cin>>H>>W;
  vector<vector<ll>> a(H,vector<ll>(W));
  vector<vector<ll>> b(H,vector<ll>(W));
  vector<vector<ll>> c(H,vector<ll>(W));
  rep(i,H)rep(j,W) cin>>a[i][j];
  rep(i,H)rep(j,W) cin>>b[i][j];
  rep(i,H)rep(j,W) c[i][j]=b[i][j]-a[i][j];
  vector<vector<vector<bool>>> dp(H,vector<vector<bool>>(W,vector<bool>(82*(H+W),false)));
  dp[0][0][abs(c[0][0])]=true;
  
  rep(i,H)rep(j,W)rep(k,82*(H+W)){
    if (i<H-1 && dp[i][j][k]){
      dp[i+1][j][k+abs(c[i+1][j])]=true;
      dp[i+1][j][abs(k-abs(c[i+1][j]))]=true;
    }
    if (j<W-1 && dp[i][j][k]){
      dp[i][j+1][k+abs(c[i][j+1])]=true;
      dp[i][j+1][abs(k-abs(c[i][j+1]))]=true;
    }
  }
  
  ll ans=INF;
  rep(i,82*(H+W)){
    if (dp[H-1][W-1][i]) ans=i<ans ? i : ans;
  }
  cout<<ans<<endl;
  
  return 0;
}
