n,m = map(int,input().split()) mod = 10**9+7 N = m+5 fact = [1]*N finv = [1]*N for i in range(2,N): fact[i] = (fact[i-1]*i)%mod finv[-1] = pow(fact[-1],mod-2,mod) for i in range(1,N)[::-1]: finv[i-1] = (finv[i]*i)%mod def nCr(n,r): if r > n: return 0 else: return fact[n]*finv[r]%mod*finv[n-r]%mod ans = 0 for i in range(1,m+1): calc = nCr(m,i)*pow(i,n,mod) if (m-i)%2: calc = -calc ans += calc ans %= mod print(ans)