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