#include <bits/stdc++.h>

#define int int64_t

const int N=1e5+9, N2=2e5+9;

using namespace std;

signed main(){
	int a, b;
	vector<int> vc, vs;

	cin >> a >> b;

	if (a==b){
		for (int i=1; i<=a; i++){
			cout << -i << " " << i << " ";
		}
	}
	else if (a>b){
		int i=1, mn=0, pl=0;
		for (; i<=b; i++){
			vc.push_back(i);
			vc.push_back(-i);
		}
		for (;i<=a; i++){
			vs.push_back(i*1000);
			vc.back()+=-i*1000;
		}

		for (int k:vc){
			cout << k << " ";
			if (k<0) mn+=k;
			else pl+=k;
		}
		for (int k:vs){
			cout << k << " ";
			if (k<0) mn+=k;
			else pl+=k;
		}

		cerr << '\n' << pl << " " << mn;
	}
	else {
		int i=1, mn=0, pl=0;
		for (; i<=a; i++){
			vc.push_back(-i);
			vc.push_back(i);
		}
		for (;i<=b; i++){
			vs.push_back(-i*1000);
			vc.back()+=i*1000;
		}

		for (int k:vc){
			cout << k << " ";
			if (k<0) mn+=k;
			else pl+=k;
		}
		for (int k:vs){
			cout << k << " ";
			if (k<0) mn+=k;
			else pl+=k;
		}

		cerr << '\n' << pl << " " << mn;
	}
}
#include <iostream>
#include <set> 
#include <iterator>
#include <bitset> 
#include <bits/stdc++.h> 
using namespace std;
typedef  long long int ll;
ll mod=1000000007;
ll power(ll x,ll y, ll p)
{
    ll res = 1;     // Initialize result
 
    x = x % p; // Update x if it is more than or
                // equal to p
  
    if (x == 0) return 0; // In case x is divisible by p;
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
 
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
 

int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        ll n,p ;
        cin>>n>>p;
        if(n==1)
        {
            cout<<p-1;
            return 0;
        }
        if(p==2)
        {
            cout<<0;return 0;
        }
        cout<<(power(p-2,n-1,mod)%mod*(p-1)%mod)%mod;
        
        
        
    
        
    
        
    }
    return 0;
}
