integer(16) H,W,ans,i
read*,H,W
ans=huge(ans)
do i=1,H-1
  ans=min(ans,maxmin(i,H,W))
end do
do i=1,W-1
  ans=min(ans,maxmin(i,W,H))
end do

print"(i0)",ans

contains
function maxmin(n,H,W)
  integer(16),intent(in)::n,H,W
  integer(16) a,b,c
  integer(16) maxmin
  a=n*W
  b=(H-N)*((W+1)/2)
  c=(H-N)*(W/2)
  maxmin=max(a,b,c)-min(a,b,c)
end function
end