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