program chocolate_bar
  implicit none
  integer :: h, w, i
  integer(8) :: m, s1, s2, s3
  read(*,*) h, w
  if (h < w) then
    h = xor(h,w)
    w = xor(h,w)
    h = xor(h,w)
  end if
  if (mod(h,3)*mod(w,3) == 0) then
    write(*,'(i0)') 0
    stop
  end if
  m = w
  do i = 1, h-1
    s1 = int(i,8)*int(w,8)
    s2 = int(h-i,8)*int(w/2,8)
    s3 = int(h-i,8)*int(w-w/2,8)
    m = min(m,max(s1,s2,s3)-min(s1,s2,s3))
  end do
  write(*,'(i0)') m
end program chocolate_bar