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