let () = Scanf.scanf "%d %d" (fun h w ->
  begin List.concat @@ List.map (fun (h, w) ->
    begin List.concat @@ List.map (fun d1 ->
      List.map (fun d2 ->
         let h1 = h / 3 + d1 in
         let h2 = h / 3 + d2 in
         let h3 = h - h1 - h2 in
         if 0 <= h3 then [h1 * w; h2 * w; h3 * w] else []) [0; 1; 2]) [0; 1; 2] end @
    begin List.concat @@ List.map (fun d1 ->
      List.map (fun d2 ->
        let h1 = h / 3 + d1 in
        let h2 = h - h1 in
        let w1 = w / 2 + d2 in
        let w2 = w - w1 in
        if 0 <= h2 && 0 <= w2 then [h1 * w; h2 * w1; h2 * w2] else []) [0; 1]) [0; 1; 2] end) [(h, w); (w, h)] end
  |> List.map (function [] -> 1145141919810 | s :: ss -> List.fold_left max s ss - List.fold_left min s ss)
  |> List.fold_left min 1145141919810
  |> Printf.printf "%d\n")
