#include <bits/stdc++.h>
 
typedef long long int ll;
const int MOD = 1000000007;
using namespace std;
int mod_expo(ll x, ll y){	
    int res = 1;    
    while (y > 0){
        if (y & 1) res = 1LL* (res*x) % MOD; 
        x = (x * x) % MOD; y = y >> 1;
    }
    return res % MOD;
}
int main(){ 
    ll n, p; cin >> n >> p;
    cout << (p-1) * mod_expo(p-2, n-1) % MOD << "\n";
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; 
}

	
#include <bits/stdc++.h>
using namespace std;

int main() {

    int N, K;
    cin >> N >> K;

    vector<vector<int>> mansion(N, vector<int>(K));

    int count = 0;
    for (int i = 1; i < N + 1; i++) {
        for (int j = 1; j < K + 1; j++) {
            count += 100*i + j;
        }
    }
 
    cout << count << endl;
}