main = interact $ show . sol . map read . words

sol [h,w] 
  | h `mod` 3==0 || w `mod` 3==0  = 0
  | otherwise                     = minimum $ concatMap f [(h,w), (w,h)]

f (x,y) = [x, x*a - (x `div` 2)*(y-a), ((x+1) `div` 2)*(y-a') - x*a']
  where
  (a,a') = ((y+2) `div` 3, y `div` 3)