N, M = map(int, input().split()) MOD = 10 ** 9 + 7 fact = [1] * (M + 1) rfact = [1] * (M + 1) r = 1 for i in range(1, M + 1): fact[i] = r = r * i % MOD rfact[M] = r = pow(fact[M], -1, MOD) for i in range(M, 0, -1): rfact[i - 1] = r = r * i % MOD # nCk (mod MOD) を求める def comb(n, k): return fact[n] * rfact[k] * rfact[n - k] % MOD ans = 0 tmp = 1 for i in reversed(range(1, M + 1)): ans += pow(i, N, MOD) * comb(M, i) * tmp ans %= MOD tmp *= -1 print(ans)