import Control.Arrow
main=print.solve.map read.words=<<getLine
solve[h,w]=minimum$f h w++f w h
f x y=map(g x=<<(y-))[1..(y+1)`div`2]
g x y i=min(h x y z)(h y x z)where z=i*x
h x y z=uncurry(-)$(maximum&&&minimum)[z,x*d,x*(y-d)]where d=y`div`2