#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
#define s (160*80)
typedef long long ll;
bool dp[89][89][s*2];

int main(){
  int h,w;
  int a[89][89],b[89][89];
  cin>>h>>w;
  rep(i,h)rep(j,w){
    cin>>a[i][j];
  }
  rep(i,h)rep(j,w){
    cin>>b[i][j];
  }

  dp[0][0][s]=1;
  rep(i,h){
    rep(j,w){
      rep(k,s*2){
        int d=abs(a[i][j]-b[i][j]);
        if(k+d<s*2){
          dp[i+1][j][k+d]|=dp[i][j][k];
          dp[i][j+1][k+d]|=dp[i][j][k];
        }
        if(k-d>=0){
          dp[i+1][j][k-d]|=dp[i][j][k];
          dp[i][j+1][k-d]|=dp[i][j][k];
        }
      }
    }
  }

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

  return(0);
}
