let a, b = Scanf.scanf "%d %d\n" (fun a b -> a, b)
let rec pow n x =
  match n with
  | 1 -> x
  | n' -> x * pow (n'-1) x

let ans =
  if a = 1 then b
  else b * pow (a-1) (b-1)

let () =
  print_int ans; print_newline ()