import Control.Applicative

getInt :: IO Int
getInt = (\a -> read a :: Int) <$> getLine
getIntArray :: IO [Integer]
getIntArray = ((map (\a -> read a :: Integer)) . words) <$> getLine

main = do
    [n, k] <- getIntArray
    print $ (*) k $ (k - 1) ^ (n - 1)
