#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; ll mod = 1000000007; ll modsize = 500010; vector fac(modsize); vector inv(modsize); vector facinv(modsize); void modcalc(){ if(modsize == 0) abort(); fac[0] = 1; fac[1] = 1; inv[1] = 1; facinv[0] = 1; facinv[1] = 1; for(ll i = 2 ; i < modsize ; i++){ fac[i] = fac[i-1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; facinv[i] = facinv[i-1] * inv[i] % mod; } } ll modinv(ll a){ if(a==0) abort(); ll b = mod, u = 1, v = 0; while(b){ ll t = a/b; a -= t * b; swap(a,b); u -= t * v; swap(u,v); } u %= mod; if(u<0) u += mod; return u; } ll modpow(ll a,ll b){ ll ans = 1; a %= mod; while(b){ if(b&1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } ll modcomb(ll n, ll k){ if(n<0||k<0||n0)) return 0; if(n==0&&k==0) return 1; return fac[n+k-1] * facinv[k] % mod * facinv[n-1] % mod; } int main(){ cin.tie(0); ios::sync_with_stdio(0); modcalc(); ll N,M; cin >> N >> M; ll ans = 0; rep(i,M+1){ ll cur = (i & 1 ? +1 : mod - 1) * modcomb(M, i) % mod * modpow(i, N) % mod; ans = (ans + cur) % mod; } cout << ans << endl; }