import Control.Monad
import Data.List

main=do
    [n,m]<-map read.words<$>getLine::IO[Int]
    print $  minimum $ map (liftM2 (-) maximum minimum) (sep n m ++ sep m n)

sep n m = map (\k -> (m*k:(d2 m (n-k)))) [1..n-1]

d2 a b
    | even a = [(b*a)`div`2]
    | even b = [(b*a)`div`2]
    | a > b = [(a`div`2)*b, (a`div`2+1)*b]
    | a <= b = [(b`div`2)*a, (b`div`2+1)*a]
