let diff3 a b c = max a (max b c) - min a (min b c)
let calc a b =
  let sub_calc s0 a' b' =
    let d0 = diff3 s0 (a'/2*b') ((a'-a'/2)*b') in
    let d1 = diff3 s0 (b'/2*a') ((b'-b'/2)*a') in
    min d0 d1
  in
  [ sub_calc (a/3*b) (a-a/3) b;
    sub_calc ((a+3)/3*b) (a-(a+3)/3) b;
    sub_calc (b/3*a) a (b-b/3);
    sub_calc ((b+3)/3*a) a (b-(b+3)/3);
  ] |> List.fold_left min 1010101010101010
let h, w = Scanf.scanf "%d %d" (fun x y -> x, y)
let () = calc h w |> Printf.printf "%d\n"
