mod = 1000000007 p, k = map(int, input().split()) dp0, dp1 = 1, 0 for i in range(k): dp0, dp1 = ((p + 1) * dp0 + 2 * dp1) % mod, (p - 1) * (dp0 + 2 * dp1) % mod print(dp0)