#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;

ll H, W;
ll A[85][85], B[85][85];
ll AB[85][85];

const ll D = 160 * 80 + 10; // あり得る長さ
const ll D2 = D * 2; // あり得る値の範囲
typedef bitset<D2> bs;

// [r][c] にきたときに、この値はあり得るか。0 or 1
bs dp[85][85];

int main() {
    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) AB[i][j] = abs(A[i][j] - B[i][j]);

    dp[0][0][D - AB[0][0]] = 1;
    dp[0][0][D + AB[0][0]] = 1;

    rep(i, H)rep(j, W) {
        if (i) {
            // たす
            dp[i][j] |= dp[i - 1][j] << AB[i][j];
            // 引く
            dp[i][j] |= dp[i - 1][j] >> AB[i][j];
        }

        if (j) {
            // たす
            dp[i][j] |= dp[i][j - 1] << AB[i][j];
            // 引く
            dp[i][j] |= dp[i][j - 1] >> AB[i][j];
        }
    }

    // 答えを求める D の分を戻す
    ll ans = INF;
    rep(i, D2) {
        if (dp[H - 1][W - 1][i]) ans = min(ans, abs(i - D));
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W)), B(H, vector<int>(W));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> A.at(i).at(j);
        }
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> B.at(i).at(j);
        }
    }

    vector<vector<int>> d(H, vector<int>(W));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            d.at(i).at(j) = abs(A.at(i).at(j) - B.at(i).at(j));
        }
    }

    auto to_id = [&](int i, int j) {
        return i * W + j;
    };
    vector<vector<bool>> dp(H * W, vector<bool>(80 * 160 + 1));
    dp.at(to_id(0, 0)).at(d.at(0).at(0)) = true;
    for (int i = 1; i < H; i++)
    {
        for (int k = 0; k < 80 * 160 + 1; k++)
        {
            if (dp.at(to_id(i - 1, 0)).at(k))
            {
                dp.at(to_id(i, 0)).at(abs(k + d.at(i).at(0))) = true;
                dp.at(to_id(i, 0)).at(abs(k - d.at(i).at(0))) = true;
            }
        }
    }
    for (int j = 1; j < W; j++)
    {
        for (int k = 0; k < 80 * 160 + 1; k++)
        {
            if (dp.at(to_id(0, j - 1)).at(k))
            {
                dp.at(to_id(0, j)).at(abs(k + d.at(0).at(j))) = true;
                dp.at(to_id(0, j)).at(abs(k - d.at(0).at(j))) = true;
            }
        }
    }
    for (int i = 1; i < H; i++)
    {
        for (int j = 1; j < W; j++)
        {
            for (int k = 0; k < 80 * 160 + 1; k++)
            {
                if (dp.at(to_id(i - 1, j)).at(k))
                {
                    dp.at(to_id(i, j)).at(abs(k + d.at(i).at(j))) = true;
                    dp.at(to_id(i, j)).at(abs(k - d.at(i).at(j))) = true;
                }
                if (dp.at(to_id(i, j - 1)).at(k))
                {
                    dp.at(to_id(i, j)).at(abs(k + d.at(i).at(j))) = true;
                    dp.at(to_id(i, j)).at(abs(k - d.at(i).at(j))) = true;
                }
            }
        }
    }
    for (int k = 0; k < 80 * 160 + 1; k++)
    {
        if (dp.at(to_id(H - 1, W - 1)).at(k))
        {
            cout << k << endl;
            break;
        }
    }
    return 0;
}
