#include<bits/stdc++.h>
#define pb push_back
typedef long long goo;
using namespace std;
int read(){
    char ch;
    int input = 0, num = 1;
    do{
        ch = getchar();
        if(ch == '-') num=-1;
    }
    while(ch < '0' or ch > '9');
    while(ch >= '0' and ch <= '9'){
        input = input * 10 + ch - '0';
        ch = getchar();
    }
    return input * num;
}
int main()
{
    int n=read(),k=read();
    int ans=k;
    for(int i=2;i<=n;i++)
        ans*=k-1;
    cout<<ans;
    return 0;
}
