P,K = map(int,input().split()) dp = [[0,0] for i in range(K+1)] mod = 10**9+7 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[K][0])