import           Control.Monad
import           Data.Array.Unboxed
import           Data.List.Split
import           Data.List

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  print $ k * (k - 1) ^ (n - 1)
