#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define _roverload(_a1,_a2,_a3,name,...) name
    #define _rep(i,n) repi(i,0,n)
    #define repi(i,a,b) for(int i=int(a);i<int(b);++i)
    #define rep(...) _roverload(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
    #define _rrep(i,n) rrepi(i,0,n)
    #define rrepi(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);--i)
    #define rrep(...) _roverload(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    void print() {cout << '\n';}
    template<class T> void print(const vector<T> &v)
    {bool f=false; for(const auto &e: v){if(f)cout << ' '; cout << e; f=true;} cout << '\n';}
    template<class... T> void print(const T&... args)
    {bool f=false; for(const auto &e: {args...}){if(f)cout << ' '; cout << e; f=true;} cout << '\n';}
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
const int MOD = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
    bool operator==(const mint a) const {
        return x == a.x;
    }
    bool operator!=(const mint a) const {
        return x != a.x;
    }
    friend ostream& operator<<(ostream& os, const mint& value) {
        os << value.x;
        return os;
    }
    friend istream& operator>>(istream& is, mint& value) {
        ll t;
        is >> t;
        value = mint(t);
        return is;
    }
};

#pragma endregion library

int main(){
    int n, p; cin >> n >> p;
    mint el = p-2;
    el = el.pow(n-1);
    print(el*(p-1));
}
#include <iostream>
using namespace std;
int main() {
  int N,W;
 
  cin>>N>>W;
  cout<<N/W;
  
  return 0;
}