import Text.Regex

main::IO()
main =do
  nk<-getLine
  let n:k:[] =  map read (words nk)::[Int]
  print (solver n k)

solver:: Int -> Int -> Int
solver 0 _ =1
solver 1 k =k
solver n k = (k-1)* solver (n-1) k 