N, K = map(int, input().split()) mod = int(1e9) + 7 def inved(a): x, y, u, v, k, l = 1, 0, 0, 1, a, mod while l: x, y, u, v = u, v, x - u * (k // l), y - v * (k // l) k, l = l, k % l return x % mod def doubling(n, m): y = 1 tmp = m bas = n while tmp: if tmp % 2: y *= bas y %= mod bas *= bas bas %= mod tmp >>= 1 return y print(doubling(K, N)*(doubling(K+3, N) - doubling(K+1, N))*inved(doubling(2, N))%mod)