main = do
  [h, w] <- map read . words <$> getLine
  putStrLn . show $ solve h w

solve:: Int -> Int -> Int
solve h w = minimum $ map calcD $ (calc h w) ++ (calc w h)

calcD:: [Int] -> Int
calcD a = (maximum a) - (minimum a)

calc:: Int -> Int -> [[Int]]
calc h w = concat [[s1:(cut (h - hh) w), s1:(slice (h - hh) w)] | hh <- [1..(h - 1)], s1 <- [w * hh]]

slice:: Int -> Int -> [Int]
slice h w = [h1 * w, (h - h1) * w] where
  h1 = div h 2

cut:: Int -> Int -> [Int]
cut h w = [h * w1, h * (w - w1)] where
  w1 = div w 2