P, K = map(int, input().split()) mod = 10 ** 9 + 7 nz = 1 nnz = 0 for i in range(K): nz1 = (nz * (P + 1) + nnz * 2) % mod nnz1 = (nz * (P - 1) + nnz * (2 * P - 2)) % mod nz = nz1 nnz = nnz1 print(nz)