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

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
ulong MIDDLE = 100_000;
alias Pair = Tuple!(long, "flag", long, "num");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

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

void main()
{
    long h, w;
    scan(h, w);
    long min_dif = INF;
    foreach(i; iota(1, w))
    {
        long split = h * i, rest = h * (w - i);
        long middle1 = h / 2, middle2 = (w - i) / 2;
        long right = (w - i) * middle1, left = (w - i) * (h - middle1);
        long upper = h * middle2, lower = h * (w - i - middle2);
        auto dif1 = only(split, right, left).reduce!(max) - only(split, right, left).reduce!(min); 
        auto dif2 = only(split, upper, lower).reduce!(max) - only(split, upper, lower).reduce!(min);
        min_dif = only(dif1, dif2, min_dif).reduce!(min);
    }
    foreach(i; iota(1, h))
    {
        long split = w * i, rest = w * (h - i);
        long middle1 = w / 2, middle2 = (h - i) / 2;
        long right = (h - i) * middle1, left = (h - i) * (w - middle1);
        long upper = w * middle2, lower = w * (h - i - middle2);
        auto dif1 = only(split, right, left).reduce!(max) - only(split, right, left).reduce!(min); 
        auto dif2 = only(split, upper, lower).reduce!(max) - only(split, upper, lower).reduce!(min);
        min_dif = only(dif1, dif2, min_dif).reduce!(min);
    }
    min_dif.writeln();
}
