f h w = (x*w-(h-x)`div`2*w) `min` (x*w-w`div`2*(h-x))
  where x = (h+2)`div`3
g h w = ((h-x+1)`div`2*w-x*w) `min` ((w+1)`div`2*(h-x)-x*w)
  where x = h`div`3
main = do
  [h,w] <- map read . words <$> getLine :: IO [Int]
  print $ f h w `min` f w h `min` g h w `min` g w h