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

#include<string>

#include<vector>

#include<algorithm>

#include<map>

#include<set>

#include<cstdio>

#include<cmath>

#include<numeric>

#include<queue>

#include<stack>

#include<cstring>

#include<limits>

#include<functional>

#include<unordered_set>

#include<iomanip>

#include<cassert>

#include<regex>

#define rep(i,a) for(int i=(int)0;i<(int)a;++i)

#define pb push_back

#define eb emplace_back

using ll=long long;

constexpr ll mod = 1e9 + 7;

constexpr ll INF = 1LL << 50;

 

template<class T> inline bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}

template<class T> inline bool chmax(T& a, T b) {

    if (a < b) {

        a = b;

        return true;

    }

    return false;

}

using namespace std;



bool dp[85][85][13005];



void solve(){

    int h,w;

    cin>>h>>w;

    vector<vector<int>>a(h,vector<int>(w)),b(h,vector<int>(w));

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

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

    dp[0][0][abs(a[0][0]-b[0][0])]=true;

    rep(i,h){

      rep(j,w){

        rep(k,13001){

        if(i-1>=0){

          dp[i][j][abs(k+a[i][j]-b[i][j])]|=dp[i-1][j][k];

          dp[i][j][abs(k+b[i][j]-a[i][j])]|=dp[i-1][j][k];

        }

        if(j-1>=0){

          dp[i][j][abs(k+a[i][j]-b[i][j])]|=dp[i][j-1][k];

          dp[i][j][abs(k+b[i][j]-a[i][j])]|=dp[i][j-1][k];

    }

      }

      }

    }

    rep(i,13001){

      if(dp[h-1][w-1][i]){

        cout<<i<<"\n";

        return;

      }

    }

}

 

int main(){

	ios::sync_with_stdio(false);

    cin.tie(0);

	cout<<fixed<<setprecision(15);

	solve();

	return 0;

}


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

#include<string>

#include<vector>

#include<algorithm>

#include<map>

#include<set>

#include<cstdio>

#include<cmath>

#include<numeric>

#include<queue>

#include<stack>

#include<cstring>

#include<limits>

#include<functional>

#include<unordered_set>

#include<iomanip>

#include<cassert>

#include<regex>

#include<bitset>

#define rep(i,a) for(int i=(int)0;i<(int)a;++i)

#define pb push_back

#define eb emplace_back

using ll=long long;

constexpr ll mod = 1e9 + 7;

constexpr ll INF = 1LL << 50;

 

template<class T> inline bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}

template<class T> inline bool chmax(T& a, T b) {

    if (a < b) {

        a = b;

        return true;

    }

    return false;

}

using namespace std;





void solve(){

    int h,w;

    cin>>h>>w;

    vector<vector<int>>a(h,vector<int>(w)),b(h,vector<int>(w));

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

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

    const int l=6400;

    vector<vector<bitset<2*l>>>dp(h,vector<bitset<2*l>>(w));

    dp[0][0][6400+abs(a[0][0]-b[0][0])]=1;

    rep(i,h){

      rep(j,w){

        if(i>0){

          dp[i][j]|=dp[i-1][j]<<(abs(a[i][j]-b[i][j]));

          dp[i][j]|=dp[i-1][j]>>(abs(a[i][j]-b[i][j]));

        }

        if(j>0){

          dp[i][j]|=dp[i][j-1]<<(abs(a[i][j]-b[i][j]));

          dp[i][j]|=dp[i][j-1]>>(abs(a[i][j]-b[i][j]));

        }

      }

    }

    int ans=1e6;

    rep(i,2*l){

      if(dp[h-1][w-1][i]){

        chmin(ans,abs(6400-i));

      }

    }

    cout<<ans<<"\n";

}

 

int main(){

	ios::sync_with_stdio(false);

    cin.tie(0);

	cout<<fixed<<setprecision(15);

	solve();

	return 0;

}


// Fastest known solution for this problem: