MOD = 10 ** 9 + 7 n, k = map(int, input().split()) a = 1 b = 0 for i in range(k): a, b = ((n + 1) * a + (n - 1) * 2 * b) % MOD, (a + (n - 1) * 2 * b) % MOD print(a)