import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long H, long W, long[][] A, long[][] B) {
    const L = H * W * 80;
    auto dp = new long[][][](H + 1, W + 1, L);
    auto diff0 = abs(A[0][0] - B[0][0]);
    dp[1][1][diff0 + (L / 2)] = true;
    dp[1][1][-diff0 + (L / 2)] = true;

    foreach (h; 1 .. H + 1) {
        foreach (w; 1 .. W + 1) {
            if (h == 1 && w == 1)
                continue;

            auto diff = abs(A[h - 1][w - 1] - B[h - 1][w - 1]);
            foreach (i; 0 .. L) {
                dp[h][w][i] =
                    (0 <= i - diff && dp[h - 1][w][i - diff])
                    || (i + diff < L && dp[h - 1][w][i + diff])
                    || (0 <= i - diff && dp[h][w - 1][i - diff])
                    || (i + diff < L && dp[h][w - 1][i + diff]);
            }
        }
    }

    return iota(L).filter!(i => dp[H][W][i])
        .map!(i => abs(i - (L / 2)))
        .reduce!min;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long H;
    H = input.front.to!long;
    input.popFront;

    long W;
    W = input.front.to!long;
    input.popFront;

    long[][] A = new long[][](cast(size_t) (H), cast(size_t) (W));
    foreach (i; 0 .. cast(size_t) (H)) {
        foreach (j; 0 .. cast(size_t) (W)) {
            A[i][j] = input.front.to!long;
            input.popFront;
        }
    }

    long[][] B = new long[][](cast(size_t) (H), cast(size_t) (W));
    foreach (i; 0 .. cast(size_t) (H)) {
        foreach (j; 0 .. cast(size_t) (W)) {
            B[i][j] = input.front.to!long;
            input.popFront;
        }
    }

    static if (is(ReturnType!solve == void))
        solve(H, W, A, B);
    else {
        auto ans = solve(H, W, A, B);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}
