program main
implicit none
integer :: i, j, n, k

read(*,*) n, k
if( n == 1 ) then
   write(*,'(i0)') k
else
   i = k
   do j = 1, n-1
      i = i*(k-1)
   end do
   write(*,'(i0)') i
end if


end program main
