let () =
  let n,k = Scanf.scanf "%d %d " (fun a b -> a,b) in
  let pow a n =
    let rec aux res a n =
      if n = 0 then res else aux (res*a) a (n-1)
    in
    aux 1 a n
  in
  Printf.printf "%d\n" @@
  pow (k-1) (n-1) * k
