#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;
#define D 80*160
bitset<D*2>dp[89][89];

int main(){
  int h,w;
  int a[89][89];
  cin>>h>>w;
  rep(i,h)rep(j,w){
    cin>>a[i][j];
  }
  rep(i,h)rep(j,w){
    int x;
    cin>>x;
    a[i][j]=abs(a[i][j]-x);
  }

  dp[0][0][D+a[0][0]]=1;
  dp[0][0][D-a[0][0]]=1;
  rep(i,h)rep(j,w){
    if(i){
      dp[i][j]|=dp[i-1][j]<<a[i][j];
      dp[i][j]|=dp[i-1][j]>>a[i][j];
    }
    if(j){
      dp[i][j]|=dp[i][j-1]<<a[i][j];
      dp[i][j]|=dp[i][j-1]>>a[i][j];
    }
  }

  int ans=INF;
  rep(i,D*2){
    if(dp[h-1][w-1][i]){
      ans=min(ans,abs(i-D));
    }
  }

  cout<<ans<<endl;

  return(0);
}
