open Printf
open Scanf
open Num

let () =
  let h, w = scanf "%d %d\n" (fun x y -> (x, y)) in
  let f1 () = if h mod 3 = 0 then 0 else w in
  let f2 () = if w mod 3 = 0 then 0 else h in
  let f3 () =
    let w1 = w / 2 in
    let w2 = w - w1 in
    let rec loop a s =
      if a = h then s
      else
        let x = (num_of_int a) */ (num_of_int w) in
        let y = (num_of_int (h - a)) */ (num_of_int w1) in
        let z = (num_of_int (h - a)) */ (num_of_int w2) in
        let mi = min_num (min_num x y) z in
        let mx = max_num (max_num x y) z in
        if s >/ (mx -/ mi) then loop (a+1) (mx -/ mi) else loop (a+1) s in
    int_of_num (loop 1 (num_of_int w */ num_of_int h)) in
  let f4 () =
    let h1 = h /2 in
    let h2 = h - h1 in
    let rec loop a s =
      if a = w then s
      else
        let x = (num_of_int a) */ (num_of_int h) in
        let y = (num_of_int (w - a)) */ (num_of_int h1) in
        let z = (num_of_int (w - a)) */ (num_of_int h2) in
        let mi = min_num (min_num x y) z in
        let mx = max_num (max_num x y) z in
        if s >/ (mx -/ mi) then loop (a+1) (mx -/ mi) else loop (a+1) s in
    int_of_num (loop 1 (num_of_int w */ num_of_int h)) in
  min (min (f1 ()) (f2 ())) (min (f3 ()) (f4 ())) |> printf "%d\n"
