import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long h, w;
    scan(h, w);
    long ans = INF;
    foreach (i; iota(1, h))
    {
        long a, b, c, r;
        a = i * w;
        r = h * w - a;
        if ((h - i) % 2 == 0 || w % 2 == 0)
        {
            b = c = r / 2;
            ans = min(ans, abs(a - b));
        }
        else
        {
            b = (max(h, w) / 2) * min(h - i, w);
            c = r - b;
            ans = min(ans, only(abs(a - b), abs(a - c), abs(b - c)).array().reduce!(max));
        }
    }
    foreach (j; iota(1, w))
    {
        long a, b, c, r;
        a = j * h;
        r = h * w - a;
        if (h % 2 == 0 || (w - j) % 2 == 0)
        {
            b = c = r / 2;
            ans = min(ans, abs(a - b));
        }
        else
        {
            b = max(h, w) / 2 * min(h, w - j);
            c = r - b;
            ans = min(ans, only(abs(a - b), abs(a - c), abs(b - c)).array().reduce!(max));
        }
    }
    ans.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
