// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <algorithm>

#include <cctype>

#include <cmath>

#include <queue>

#include <map>

#include <numeric>

#include <unordered_map>

#include <iomanip>

#include <functional>

#include <bitset>

#include <complex>

#include <stack>

#include <cstdint>







#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 repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)

#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)



#define all(x) (x).begin(),(x).end()



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

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



typedef long long ll;



using namespace std;





int main()

{

  ios::sync_with_stdio(false);

  cin.tie(0);

  ll h,w;cin>>h>>w;

  vector<vector<ll>>a(h,vector<ll>(w));

  auto b=a;

  rep(i,h)rep(j,w)cin>>a[i][j];

  rep(i,h)rep(j,w)cin>>b[i][j];

  ll geta=80*160,sz=geta*2+7;

  vector<vector<vector<bool>>>dp(h,vector<vector<bool>>(w,vector<bool>(geta*2+7)));

  auto isin=[&](ll y,ll x){

    if(y>=0&&y<h&&x>=0&&x<w)return 1;

    return 0;

  };

  ll d=a[0][0]-b[0][0];

  dp[0][0][geta-d]=1;

  dp[0][0][geta+d]=1;

  rep(i,h)rep(j,w){

    //if(i==0&&j==0)continue;

    d=a[i][j]-b[i][j];

    rep(k,sz){

      if(isin(i-1,j)){

        if(dp[i-1][j][k]==0)continue;

        dp[i][j][k-d]=1;

        dp[i][j][k+d]=1;

      }

    }

    rep(k,sz){

      if(isin(i,j-1)){

        if(dp[i][j-1][k]==0)continue;

        dp[i][j][k-d]=1;

        dp[i][j][k+d]=1;

      }

    }

  }

  ll res=1e9;

  rep(i,sz){

    if(dp[h-1][w-1][i])chmin(res,abs(i-geta));

  }

  cout<<res<<endl;





  return 0;



}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <algorithm>

#include <cctype>

#include <cmath>

#include <queue>

#include <map>

#include <numeric>

#include <unordered_map>

#include <iomanip>

#include <functional>

#include <bitset>

#include <complex>

#include <stack>

#include <cstdint>







#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 repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)

#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)



#define all(x) (x).begin(),(x).end()



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

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



typedef long long ll;



using namespace std;





int main()

{

  ios::sync_with_stdio(false);

  cin.tie(0);

  ll h,w;cin>>h>>w;

  vector<vector<ll>>a(h,vector<ll>(w));

  auto b=a;

  rep(i,h)rep(j,w)cin>>a[i][j];

  rep(i,h)rep(j,w)cin>>b[i][j];

  const ll geta=80*160,sz=geta*2+7;

  vector<vector<bitset<sz>>>dp(h,vector<bitset<sz>>(w));

  auto isin=[&](ll y,ll x){

    if(y>=0&&y<h&&x>=0&&x<w)return 1;

    return 0;

  };

  ll d=a[0][0]-b[0][0];

  dp[0][0][geta-d]=1;

  dp[0][0][geta+d]=1;

  rep(i,h)rep(j,w){

    //if(i==0&&j==0)continue;

    d=abs(a[i][j]-b[i][j]);

    if(isin(i-1,j)){

      dp[i][j]|=dp[i-1][j]<<d;

      dp[i][j]|=dp[i-1][j]>>d;

    }

    if(isin(i,j-1)){

      dp[i][j]|=dp[i][j-1]<<d;

      dp[i][j]|=dp[i][j-1]>>d;

    }



  }

  ll res=1e9;

  rep(i,sz){

    if(dp[h-1][w-1][i])chmin(res,abs(i-geta));

  }

  cout<<res<<endl;





  return 0;



}


// Fastest known solution for this problem: