import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto hw = readln.split.to!(int[]);
    auto H = hw[0];
    auto W = hw[1];
    int[][] AS, BS;
    AS.length = H;
    BS.length = H;
    foreach (i; 0..H) {
        AS[i] = readln.split.to!(int[]);
    }
    foreach (i; 0..H) {
        BS[i] = readln.split.to!(int[]);
    }
    auto DP = new int[][][](H, W, 80*80+1);
    foreach (ref dp1; DP) foreach (ref dp2; dp1) dp2[] = -1;
    int solve(int h, int w, int d) {
        auto e = abs(AS[h][w] - BS[h][w]);
        if (h+1 == H && w+1 == W) return min(d + e, abs(d - e));
        if (DP[h][w][d] == -1) {
            int r = int.max;
            if (h+1 < H) {
                r = min(r, solve(h+1, w, d + e));
                r = min(r, solve(h+1, w, abs(d - e)));
            }
            if (w+1 < W) {
                r = min(r, solve(h, w+1, d + e));
                r = min(r, solve(h, w+1, abs(d - e)));
            }
            DP[h][w][d] = r;
        }
        return DP[h][w][d];
    }
    writeln(solve(0, 0, 0));
}