#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

// x^n
ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

// x^{-1}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }

int main() {
  int n, p;
  cin >> n >> p;
  ll ans = p - 1;
  ans = (ans * mod_pow(p - 2, n - 1)) % MOD;
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cerr << #x << " = " << x << endl;
main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n, k;
	cin >> n >> k;
	while(k > 0){
		if(n % 200 == 0) n /= 200;
		else n = n * 1000 + 200;
		k--;
	}
	cout << n;
}