import Data.List

main = do
  [h, w] <- sort . map read . words <$> getLine :: IO [Int]
  let [w1, w2, w3, w4] = split w
      s1 = solve h w1 w2
      s2 = solve h w3 w4
  if mod h 3 == 0 || mod w 3 == 0
    then print 0
    else print $ min s1 s2

split :: Int -> [Int]
split w = let x = div w 3
          in [x + 1, w - x - 1, x, w - x]

solve :: Int -> Int -> Int -> Int
solve h w1 w2 = let x = w1 * h
                    y = w2 * (h `div` 2)
                    z = w2 * ((-) h $ h `div` 2)
                    mi = minimum [x, y, z]
                    ma = maximum [x, y, z]
                in ma - mi