import Data.List
import Data.Function

main = print . solve . map read . words =<< getLine

solve :: [Int] -> Int
solve [w,h] = minimum . map (\(a,w',h') -> solve' a w' h') $ [(w'*h,w-w',h) | w' <- [1..w]] ++ [(w*h',w,h-h') | h' <- [1..h]]

solve' a w h = minimum $ map (maximum . map score) [[wa*h,wb*h], [w*ha,w*hb]]
    where
        score = abs . subtract a
        (wa,rw) = w `quotRem` 2
        wb = wa + rw
        (ha,rh) = h `quotRem` 2
        hb = ha + rh
