N, M = map(int, input().split()) MOD = 10 ** 9 + 7 MAX = 10 ** 5 + 10 # https://tjkendev.github.io/procon-library/python/math/factorial.html から拝借しています。 fact = [1] * (MAX + 1) rfact = [1] * (MAX + 1) r = 1 for i in range(1, MAX + 1): fact[i] = r = r * i % MOD rfact[MAX] = r = pow(fact[MAX], MOD - 2, MOD) for i in range(MAX, 0, -1): rfact[i - 1] = r = r * i % MOD def comb(n, k, error=0): if not 0 <= k <= n: return error return fact[n] * rfact[k] * rfact[n - k] % MOD ans = 0 sign = 1 for i in range(M, 0, -1): ans += sign * pow(i, N, MOD) * comb(M, i) ans %= MOD sign *= -1 print(ans)