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 = (max `on` abs) (ma1 * mi - a) (ma2 * mi - a)
    where
        (ma1,r) = (max w h) `quotRem` 2
        ma2 = ma1 + r
        mi = (min w h)
