MOD = 10 ** 9 + 7 N, M = map(int, input().split()) dp = [[0] * (N - M + 1) for _ in range(M + 1)] dp[1][0] = M for i in range(M + 1): for j in range(N - M + 1): if i > 0: dp[i][j] += dp[i - 1][j] * (M - i + 1) if j > 0: dp[i][j] += dp[i][j - 1] * i dp[i][j] %= MOD print(dp[M][N - M])