import Control.Applicative
import Control.Monad
import Data.Functor
import Data.List

type Rect = (Int, Int)

rarea :: Rect -> Int
rarea (h, w) = h * w

rsplit :: Rect -> [(Rect, Rect)]
rsplit (h, w) = [((y, w), (h-y, w)) | y <- [0..h`div`2]] ++ [((h, x), (h, w-x)) | x <- [0..w`div`2]]

eqsplit :: Rect -> [(Rect, Rect)]
eqsplit (h, w) = let (y, x) = (div h 2, div w 2) in [((y, w), (h-y, w)), ((h, x), (h, w-x))]

f :: Rect -> Rect -> Rect -> Int
f p q r = let l = map rarea [p, q, r] in maximum l - minimum l

solve :: [Int] -> Int
solve [h, w] = minimum $ concatMap (\(p, q) -> map (uncurry $ f p) (eqsplit q)) $ rsplit (h, w)

main = solve <$> (map read . words <$> getLine) >>= print