import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  long h, w; readV(h, w);

  auto m = h*w;

  foreach (i; 1..h) {
    m = min(m, sub3(div2(h-i, w, true), i*w));
    m = min(m, sub3(div2(h-i, w, false), i*w));
  }

  foreach (i; 1..w) {
    m = min(m, sub3(div2(h, w-i, true), i*h));
    m = min(m, sub3(div2(h, w-i, false), i*h));
  }

  writeln(m);
}

auto div2(long h, long w, bool hv)
{
  if (hv)
    return [(h/2)*w, (h-h/2)*w];
  else
    return [h*(w/2), h*(w-w/2)];
}

auto sub3(long[] s1, long s2)
{
  auto t = (s1 ~ s2).sort();
  return t[2] - t[0];
}
