module Main where

import Control.Applicative
import Control.Monad
import Data.List

f :: Int -> Int -> Int
f h w = minimum $ fmap f [1 .. w - 1]
  where
    (h1, h2) = let (q, r) = h `divMod` 2 in (q, q + r)
    r1 i = i * h
    r2 i = (w - i) * h1
    r3 i = (w - i) * h2
    rs i = [r1 i, r2 i, r3 i]
    f i = maximum (rs i) - minimum (rs i)

main :: IO ()
main = do
    [h, w] <- fmap read . words <$> getLine :: IO [Int]

    if any ((== 0) . (`mod` 3)) [h, w]
        then print 0
        else print $ minimum [h, w, f h w, f w h]