#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

using b = bitset<6400 * 2 + 64>;


int main() {
	ll H, W;
	vector<vector<b>> f;
	vector<vector<ll>> a, b;
	cin >> H >> W;
	f.resize(H);
	a.resize(H);
	b.resize(H);
	REP(i, 0, H) {
		f[i].resize(W);
		a[i].resize(W);
		REP(j, 0, W) {
			f[i][j].reset();
			cin >> a[i][j];
		}
	}
	REP(i, 0, H) {
		b[i].resize(W);
		REP(j, 0, W) {
			cin >> b[i][j];
		}
	}
	int i0 = 6400;
	f[0][0][i0 + b[0][0] - a[0][0]] = true;
	f[0][0][i0 - b[0][0] + a[0][0]] = true;
	auto bs = [](auto& b, int d) {
		if (d >= 0) return b << d;
		else return b >> -d;
	};
	REP(j, 1, W) f[0][j] = bs(f[0][j - 1], b[0][j] - a[0][j]) | bs(f[0][j - 1], -b[0][j] + a[0][j]);
	REP(i, 1, H) f[i][0] = bs(f[i - 1][0], b[i][0] - a[i][0]) | bs(f[i - 1][0], -b[i][0] + a[i][0]);
	REP(i, 1, H)REP(j, 1, W) {
		f[i][j] = bs(f[i][j - 1], b[i][j] - a[i][j]) | bs(f[i - 1][j], b[i][j] - a[i][j]);
		f[i][j] |= bs(f[i][j - 1], -b[i][j] + a[i][j]) | bs(f[i - 1][j], -b[i][j] + a[i][j]);
	}
	for (int i = 0; i <= 6400; ++i) {
		if (f[H - 1][W - 1][i0 + i] || f[H - 1][W - 1][i0 - i]) {
			PRI(i);
			return 0;
		}
	}
	return 0;
}



#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <unordered_set>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}



int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}

int iabs(int i)
{
    if (i > 0) return i;
    else return -i;
}


int main()
{
    int H, W;
    cin >> H >> W;

    vec_t<int,2> A = make_vec<int,2>(H, W);
    vec_t<int,2> B = make_vec<int,2>(H, W);

    for (int h = 0; h < H; ++h)
        for (int w = 0; w < W; ++w)
            cin >> A[h][w];

    for (int h = 0; h < H; ++h)
        for (int w = 0; w < W; ++w)
            cin >> B[h][w];
   

    vec_t<bool,3> dp = make_vec<bool,3>(H, W, (H+W)*80, false);

    for (int h = 0; h < H; ++h)
    {
        for (int w = 0; w < W; ++w)
        {
            int d = diffabs(A[h][w], B[h][w]);
            if (h == 0 && w == 0)
            {
                dp[h][w][d] = true;
            }
            
            if (w > 0)
            {
                for (size_t i = 0; i < dp[h][w-1].size(); ++i)
                {
                    if (dp[h][w-1][i])
                    {
                        dp[h][w][i+d] = true;
                        dp[h][w][iabs(i-d)] = true;
                    }
                }
            }

            if (h > 0)
            {
                for (size_t i = 0; i < dp[h-1][w].size(); ++i)
                {
                    if (dp[h-1][w][i])
                    {
                        dp[h][w][i+d] = true;
                        dp[h][w][iabs(i-d)] = true;
                    }
                }
            }
        }
    }

    const auto &hw = dp[H-1][W-1];
    auto it = find_if(begin(hw), end(hw), [](auto b){ return b; });
    int ans = std::distance(begin(hw), it);
    cout << ans << endl;
}