N, M = map(int, input().split()) MOD = 10 ** 9 + 7 limit = 2 * 10 ** 5 fact = [1] * (limit + 1) invfact = [1] * (limit + 1) for i in range(2, limit + 1): fact[i] = fact[i - 1] * i % MOD invfact[-1] = pow(fact[-1], MOD - 2, MOD) for i in range(limit - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD def nCk(n, k): return fact[n] * invfact[n - k] % MOD * invfact[k] % MOD ans = 0 for i in range(M + 1): ans += pow(-1, M - i, MOD) * nCk(M, i) * pow(i, N, MOD) ans %= MOD print(ans)