#include <iostream>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
int main() {
  ll n,p,now,ans=1;
  cin>>n>>p;
  now=p-2;
  n--;
  while(n){
    if(n%2) {
      ans*=now;
      ans%=MOD;
    }
    now*=now;
    now%=MOD;
    n/=2;
  }
  ans*=(p-1);
  ans%=MOD;
  cout<<ans;
}
#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("a.out","w",stdout); // console output is better (in most cases)
#else
    // add i/o method of specific testing system
#endif
    int a, b;
    cin >> a >> b;
    vector<int> seq(a + b);
    int sum = 0;
    int mn = min(a, b);
    int mx = max(a, b);
    for(int i = 0; i < mx; i++)
    {
        seq[i] = i + 1;
        sum += seq[i];
    }
    for(int i = mx; i < a + b; i++)
    {
        seq[i] = -1 * (i - a + 1);
        sum += seq[i];
    }
    seq[a + b - 1] -= sum;
    for(int i : seq)
    {
        if(a > b)
        {
            cout << i << " ";
        }
        else
        {
            cout << -i << " ";

        }
    }
    cout << "\n";
    return 0;
}
