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

template<typename T>
void view_1d(vector<T> V, string sep) {
    for (ll i=0; i<V.size(); i++) {
        cout << V[i];
        if (i == V.size() - 1) {
            cout << endl;
        } else {
            cout << sep;
        }
    }
}

template<typename T>
void view_2d(vector<vector<T>> V, string sep) {
    for (ll i=0; i<V.size(); i++) {
        for (ll j=0; j<V[i].size(); j++) {
            cout << V[i][j];
            if (j == V[i].size() - 1) {
                cout << endl;
            } else {
                cout << sep;
            }
        }
    }
}

//==============================//


int main() {
    ll N, P;
    cin >> N >> P;

    ll BASE = 1000000007;
    ll n = N - 1;
    ll x = P - 2;
    ll ans = P - 1;
    while (n > 0) {
        if (n & 1) ans = ans * x % BASE;
        x = x * x % BASE;
        n >>= 1;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int A;
  int B;
  cin >> A >> B;
  
  A >= 0;
  B <= 2 * A + 100;
  B <= 1000;
  
  
  
  cout << 2 * A + 100 - B << endl;
  
}