p, k = map(int, input().split()) MOD = 10 ** 9 + 7 dp = [[0] * 2 for i in range(k + 1)] dp[0][0] = 1 for i in range(k): dp[i + 1][0] += dp[i][0] * (p + 1) dp[i + 1][0] += dp[i][1] * 2 dp[i + 1][1] += dp[i][0] * (p - 1) + dp[i][1] * 2 *(p - 1) dp[i + 1][0] %= MOD dp[i + 1][1] %= MOD print(dp[-1][0])