#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const int MAX_D = 13000;

int H,W;
int A[85][85] = {};
int B[85][85] = {};
int D[85][85] = {};
int dp[85][85][13000] = {};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    cin >> H >> 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) D[i][j] = abs(A[i][j]-B[i][j]);

    //REP(i,H) {
    //    REP(j,W){
    //        cout << D[i][j] << " ";
    //    }
    //    cout << endl;
    //}

    dp[0][0][D[0][0]+MAX_D/2] = 1;
    dp[0][0][-D[0][0]+MAX_D/2] = 1;
    FOR(i,1,W){
        REP(k,MAX_D){
            if(k-D[0][i] >= 0) chmax(dp[0][i][k] , dp[0][i-1][k-D[0][i]]);
            if(k+D[0][i] < MAX_D) chmax(dp[0][i][k] , dp[0][i-1][k+D[0][i]]);
        }
    }

    FOR(i,1,H){
        REP(k,MAX_D){
            if(k-D[i][0] >= 0) chmax(dp[i][0][k], dp[i-1][0][k-D[i][0]]);
            if(k+D[i][0] < MAX_D) chmax(dp[i][0][k], dp[i-1][0][k+D[i][0]]);
        }
    }

    FOR(i,1,H){
        FOR(j,1,W){
            REP(k,MAX_D){
                if(k-D[i][j] >= 0) chmax(dp[i][j][k], dp[i-1][j][k-D[i][j]]);
                if(k+D[i][j] < MAX_D) chmax(dp[i][j][k], dp[i-1][j][k+D[i][j]]);

                if(k-D[i][j] >= 0)chmax(dp[i][j][k], dp[i][j-1][k-D[i][j]]);
                if(k+D[i][j] < MAX_D)chmax(dp[i][j][k], dp[i][j-1][k+D[i][j]]);
            }
        }
    }

    //cout << "coord(0 0) " << endl;
    //for(int i = 0; i <= 3200; i++){
    //    if(dp[0][0][3200+i] == 1 || dp[0][0][3200-i]){
    //        cout << i << " ";
    //    }
    //}
    //cout << endl;

    //cout << "coord 0 1" << endl;
    //for(int i = 0; i <= 3200; i++){
    //    if(dp[0][1][3200+i] == 1 || dp[0][1][3200-i]){
    //        cout << i << " ";
    //    }
    //}
    //cout << endl;

    //cout << "coord 1 0" << endl;
    //for(int i = 0; i <= 3200; i++){
    //    if(dp[1][0][3200+i] == 1 || dp[1][0][3200-i]){
    //        cout << i << " ";
    //    }
    //}
    //cout << endl;
 
    for(int i = 0; i <= MAX_D/2; i++){
        if(dp[H-1][W-1][MAX_D/2+i] == 1 || dp[H-1][W-1][MAX_D/2-i]){
            cout << i << endl;
            return 0;
        }
    }
    return -1;


}

Measured memory_bytes: 345088