#include using namespace std; typedef long long ll; typedef long double ld; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b0;k>>=1){ if(k&1){ res=(res*n)%m; } n=(n*n)%m; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,m;cin >> n >> m; if(m>n){ cout << 0 << endl; } vector t(n+1); t[0]=1; for(int i=1;i<=n;i++){ (t[i]=t[i-1]*n)%=mod; } COMinit(); ll ans=0; for(ll i=m;i>=1;i--){ ll tmp=pow_mod(i,n,mod)*com(m,i)%mod; if((m-i)%2==0){ (ans+=tmp)%=mod; } else{ (ans+=-tmp+mod)%=mod; } } cout << ans << endl; }