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