/**

    ___         ___           ____        __      __        ____         ___        _    _     ____
   / __ \      / __ \        / __ \       \ \    / /       / __ \       |  _ \     | |  | |  _/  _/
  | |  \ \    / /  | |      / /  \ \       \ \  / /       / /  \ \      | | \ \    | |  | |_/  _/
  | |   \ \  / /   | |     / /____\ \       \ \/ /       / /____\ \     | |  \ \   | |  |    _/
  | |    \ \/ /    | |    / /______\ \       \  /       / /______\ \    | |   \ \  | |  |  _ \__
  | |     \__/     | |   / /        \ \       | |      / /        \ \   | |    \ \_| |  | | \__ \__
  |_|              |_|  /_/          \_\  .   |_|     /_/          \_\  |_|     \ ___|  |_|    \___\


   ________         ____         _________   ___________    __________      ___________     _________
  |  ____  \       / __ \       | _______/  |____  _____|  /  ______  \    / _________/    |___   ___|
  | |____|  \     / /  \ \      | |______        | |      /  /       \ \   | /                 | |
  |    ____ /    / /____\ \     |______  |       | |     /  /         \ \  | |  _________      | |
  | |\_\        / /______\ \           | |       | |     \  \         / /  | | |_______  |     | |
  | |  \_\     / /        \ \   _______| |       | |      \  \_______/ /   | |_________| |  ___| |___
  |_|    \_\  /_/          \_\  \________|       |_|       \__________/    \_____________| |_________|


**/

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

///Basic Debugging macros!
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(ll __i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(ll __i__=0;__i__<r;__i__++){for(ll __j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}

using namespace std;

///Power of 2 till 2^31!
ll pow2[32] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648};

///Power function!
ll power(ll x,ll y)
{
        ll res = 1;
        while(y>0){
            if(y&1)
                res *= x;
            y>>=1;
            x*=x;
        }
        return res;
}

///Basic Sieve of Eratosthenes!
void Sieve(ll n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (ll p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

bool isPerfectSquare(ll x){ ll s = sqrt(x); return (s*s == x);}

bool isFibonacci(int n){return isPerfectSquare(5*n*n + 4) || isPerfectSquare(5*n*n - 4);}

bool isPrime(int n){if (n <= 1)return false;if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0)return false;
    return true;
}
const int MOD = 1000000007;
const long double PI = 4*atan((long double)1);
const ll INF = 1e18;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int k;
    cin>>k;
    ll ans = k;
    n--;
    while(n--){
        ans *= (k-1);
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 256