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

strToInt s = (read :: String -> Int)

acut :: Int -> Int -> Int
acut h w 
  | h `mod` 3 == 0 = 0
  | otherwise = w

bcut :: Int -> Int -> Int
bcut h w = minimum [bcutsub h w c | c <-[1..(h-1)]]


bcutsub :: Int -> Int -> Int -> Int
bcutsub h w l = maximum [abs(a-b),abs(b-c),abs(c-a)]
                where a = (h-l) * (w `div` 2)
                      b = w * (h-l) - a
                      c = w * l



main = do

    [h,w] <- (map read . words) <$> getLine
    
    print (minimum [(acut h w) , (bcut h w) , (acut w h) , (bcut w h)])
    