# for n in range(5): # kouho = [] # for i in range(1 << n): # res = 0 # for j in range(n): # if (i >> j) & 1: # res += pow(2, j) # else: # res -= pow(2, j) # kouho.append(res) # print(kouho) mod = 10 ** 9 + 7 n, k = map(int, input().split()) ans = [0] * n if n % 2: # 奇数 cycle = 2 * (n // 2) rui = pow(2, k - 1, mod) num, rem = rui // n, rui % n for i in range(n): temp = (2 * i + 1) % n ans[temp] += 1 ans[-temp] += 1 for i in range(n): ans[i] *= num for i in range(rem): temp = (2 * i + 1) % n ans[temp] += 1 ans[-temp] += 1 inv = pow(2, k, mod) inv = pow(inv, mod - 2, mod) for a in ans: res = a % mod res *= inv print(res % mod) else: # 奇数 rui = pow(2, k - 1, mod) num, rem = rui // n, rui % n for i in range(n): temp = (2 * i + 1) % n ans[temp] += 1 ans[-temp] += 1 for i in range(n): ans[i] *= num for i in range(rem): temp = (2 * i + 1) % n ans[temp] += 1 ans[-temp] += 1 inv = pow(2, k, mod) inv = pow(inv, mod - 2, mod) for a in ans: res = a % mod res *= inv print(res % mod)