#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,k,ans=1;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		if(i%2)
			ans*=k;
		else
			ans*=(k-1);
	printf("%d",ans);
	//return 0;
}