Construct a sequence a = {a_1,\ a_2,\ ...,\ a_{2^{M + 1}}} of length 2^{M + 1} that satisfies the following conditions, if such a sequence exists.
 - Each integer between 0 and 2^M - 1 (inclusive) occurs twice in a.
 - For any i and j (i < j) such that a_i = a_j, the formula a_i \ xor \ a_{i + 1} \ xor \ ... \ xor \ a_j = K holds.
What is xor (bitwise exclusive or)?
The xor of integers c_1, c_2, ..., c_n is defined as follows:
 - When c_1 \ xor \ c_2 \ xor \ ... \ xor \ c_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among c_1, c_2, ...c_m whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.
For example, 3 \ xor \ 5 = 6. (If we write it in base two: 011 xor 101 = 110.)

-----Constraints-----
 - All values in input are integers.
 - 0 \leq M \leq 17
 - 0 \leq K \leq 10^9

-----Input-----
Input is given from Standard Input in the following format:
M K

-----Output-----
If there is no sequence a that satisfies the condition, print -1.
If there exists such a sequence a, print the elements of one such sequence a with spaces in between.
If there are multiple sequences that satisfies the condition, any of them will be accepted.

-----Sample Input-----
1 0

-----Sample Output-----
0 0 1 1

For this case, there are multiple sequences that satisfy the condition.
For example, when a = {0, 0, 1, 1}, there are two pairs (i,\ j)\ (i < j) such that a_i = a_j: (1, 2) and (3, 4). Since a_1 \ xor \ a_2 = 0 and a_3 \ xor \ a_4 = 0, this sequence a satisfies the condition.

Source: atcoder | Difficulty: MEDIUM_HARD


Solutions:
def main():
	(M, K) = map(int, input().split())
	if K == 0:
		print(*[i // 2 for i in range(2 ** (M + 1))])
	elif K >= 2 ** M or M <= 1:
		print(-1)
	else:
		nums = []
		for i in range(2 ** M):
			if i != K:
				nums.append(i)
		a = [nums[0], K, nums[0]]
		b = []
		for i in range(1, 2 ** M - 1):
			b.append(nums[i])
		b.append(K)
		for i in range(1, 2 ** M - 1):
			b.append(nums[2 ** M - 1 - i])
		print(*a, *b)

def __starting_point():
	main()
__starting_point()


def main():
	(M, K) = list(map(int, input().split()))
	if M == 1:
		if K == 0:
			print('0 0 1 1')
		else:
			print('-1')
		return
	if K >= 2 ** M:
		print(-1)
		return
	r = []
	for i in range(2 ** M):
		if i != K:
			r.append(i)
	r.append(K)
	for i in reversed(list(range(2 ** M))):
		if i != K:
			r.append(i)
	r.append(K)
	print(' '.join((str(i) for i in r)))
main()


(m, k) = list(map(int, input().split()))
if m == 0:
	if k == 0:
		print('0 0')
	else:
		print('-1')
elif m == 1:
	if k == 0:
		print('0 0 1 1')
	elif k >= 1:
		print('-1')
elif k < 2 ** m:
	l = list(range(2 ** m))
	l.pop(k)
	ans = l + [k] + l[::-1] + [k]
	print(' '.join(map(str, ans)))
else:
	print(-1)


(m, k) = list(map(int, input().split()))
if m == 1 and k == 1:
	print(-1)
elif m == 1 and k == 0:
	print('0 0 1 1')
elif 2 ** m > k:
	ans = str(k)
	y = []
	for i in range(2 ** m):
		if i == k:
			continue
		y.append(str(i))
	ans = ' '.join(reversed(y)) + ' ' + ans + ' ' + ' '.join(y) + ' ' + ans
	print(ans)
else:
	print(-1)


(M, K) = map(int, input().split())
if K >= pow(2, M):
	print(-1)
elif K == 0:
	ans = []
	for i in range(pow(2, M)):
		ans.append(i)
		ans.append(i)
	print(*ans)
else:
	num = 0
	L = []
	for i in range(pow(2, M)):
		if i == K:
			continue
		num ^= i
		L.append(i)
	if num == K:
		L2 = list(reversed(L))
		ans = L + [K] + L2 + [K]
		print(*ans)
	else:
		print(-1)


(m, k) = map(int, input().split())
if not 0 <= k < 2 ** m:
	print(-1)
	return
if m == 1:
	if k == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
else:
	L = []
	for i in range(2 ** m):
		if i != k:
			L.append(i)
	L.append(k)
	for i in range(2 ** m - 1, -1, -1):
		if i != k:
			L.append(i)
	L.append(k)
	print(*L)


(M, K) = map(int, input().split())
if M == 1:
	if K == 0:
		print('0 0 1 1')
	else:
		print(-1)
elif 1 << M <= K:
	print(-1)
else:
	ans = [n for n in range(1 << M) if n != K]
	ans.append(K)
	ans += [n for n in range((1 << M) - 1, -1, -1) if n != K]
	ans.append(K)
	print(*ans)


(m, k) = map(int, input().split())
x = [*range(1 << m)]
print(*(x + x[::-1] if k < 1 else x[:k:-1] + x[k - 1::-1] + [k] + x[:k] + x[k + 1:] + [k] if (k < 2 ** m) & (m > 1) else [-1]))


(m, k) = map(int, input().split())
if m == 0:
	if k == 0:
		print(0, 0)
	else:
		print(-1)
	return
if m == 1:
	if k == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
	return
if k < 2 ** m:
	l = [i for i in range(2 ** m) if i != k]
	l = l + [k] + l[::-1] + [k]
	print(*l)
else:
	print(-1)


(m, k) = map(int, input().split())
x = [*range(1 << m)]
print(*(k < 1 and x + x[::-1] or (k < 1 << m > 2 and [k] + x[k + 1:] + x[:k] + [k] + x[k - 1::-1] + x[:k:-1]) or [-1]))


import sys
input = sys.stdin.readline
(M, K) = list(map(int, input().split()))
if M == 1:
	if K == 0:
		print((0, 0, 1, 1))
	else:
		print(-1)
elif K >= 1 << M:
	print(-1)
else:
	a = list(range(1 << M))
	a.remove(K)
	ans = a + [K] + a[::-1] + [K]
	print(' '.join(map(str, ans)))


(m, k) = map(int, input().split())
if m == 0:
	if k == 0:
		print(0, 0)
	else:
		print(-1)
elif m == 1:
	if k == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
elif k >= 2 ** m:
	print(-1)
else:
	L = [i for i in range(2 ** m) if i != k]
	ans = L + [k] + L[::-1] + [k]
	print(*ans, sep=' ')


from itertools import chain
(m, k) = map(int, input().split())
if 0 < k < 2 ** m and m >= 2:
	print(*[str(i) for i in chain(range(0, k), range(k + 1, 2 ** m), [k], range(2 ** m - 1, k, -1), range(k - 1, -1, -1), [k])])
elif k == 0:
	print(*[str(i) for i in chain(range(0, 2 ** m), range(2 ** m - 1, -1, -1))])
else:
	print(-1)


(m, k) = map(int, input().split())
if k >= 2 ** m:
	print(-1)
elif m == 0:
	print(0, 0)
elif m == 1:
	if k == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
else:
	for i in range(2 ** m):
		if i == k:
			continue
		print(i, end=' ')
	print(k, end=' ')
	for i in range(2 ** m - 1, -1, -1):
		if i == k:
			continue
		print(i, end=' ')
	print(k)


(M, K) = map(int, input().split())
if K >= 2 ** M:
	print('-1')
	return
if M == 0:
	print(0, 0)
	return
elif M == 1:
	if K == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
	return
now = 0
for i in range(2 ** M):
	if i != K:
		now = now ^ i
print(K, end=' ')
for i in range(2 ** M):
	if i != K:
		print(i, end=' ')
print(K, end=' ')
for i in range(2 ** M):
	if 2 ** M - 1 - i != K:
		print(2 ** M - 1 - i, end=' ')


from itertools import permutations
import sys
sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def SI():
	return sys.stdin.readline()[:-1]

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1

def MI1():
	return map(int1, sys.stdin.readline().split())

def LI1():
	return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep='\n')
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
	(m, k) = MI()
	if (m, k) == (1, 1) or k >= 2 ** m:
		ans = [-1]
	elif k == 0:
		ans = list(range(1 << m))
		ans += ans[::-1]
	else:
		ans = []
		for i in range(1 << m):
			if i == k:
				continue
			ans.append(i)
		rev = ans[::-1]
		ans.append(k)
		ans += rev
		ans.append(k)
	print(*ans)
main()


(M, K) = list(map(int, input().split()))
if 2 ** M <= K:
	print(-1)
	return
if M == 0:
	print((0, 0))
elif M == 1 and K == 0:
	print((0, 0, 1, 1))
elif M == 1 and K >= 1:
	print(-1)
else:
	A = list(range(2 ** M))
	B = A[:K] + A[K + 1:]
	C = list(map(str, B + [K] + B[::-1] + [K]))
	print(' '.join(C))


import sys
from itertools import permutations
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(M, K) = list(map(int, readline().split()))
	if M == 0:
		if K == 0:
			print((0, 0))
			return
		else:
			print(-1)
			return
	elif M == 1:
		if K == 0:
			print((0, 0, 1, 1))
			return
		else:
			print(-1)
			return
	elif K >= pow(2, M):
		print(-1)
		return
	vec = [i for i in range(pow(2, M)) if i != K]
	ans = vec + [K] + vec[::-1] + [K]
	print(' '.join(map(str, ans)))
	return

def __starting_point():
	main()
__starting_point()


def main():
	(M, K) = list(map(int, input().split(' ')))
	if K >= 2 ** M:
		print(-1)
		return
	if M == 0:
		print('0 0')
		return
	if M == 1:
		if K == 0:
			print('0 0 1 1')
		else:
			print(-1)
		return
	arr = list(map(str, [i for i in range(2 ** M) if i != K]))
	rev_arr = arr.copy()
	rev_arr.reverse()
	ans = arr + [str(K)] + rev_arr + [str(K)]
	print(' '.join(ans))

def __starting_point():
	main()
__starting_point()


def solve():
	(M, K) = map(int, input().split())
	if K >= 1 << M:
		return [-1]
	if M == 1:
		if K == 0:
			return [1, 0, 0, 1]
		return [-1]
	ans = [K]
	for i in range(1 << M):
		if i != K:
			ans.append(i)
	ans.append(K)
	for i in range((1 << M) - 1, -1, -1):
		if i != K:
			ans.append(i)
	return ans
print(*solve())


(m, k) = map(int, input().split())
x = [*range(1 << m)]
print(*((x + x[::-1]) * (k < 1) or ([k] + x[k + 1:] + x[:k] + [k] + x[k - 1::-1] + x[:k:-1]) * (m > 1 <= k < 1 << m) or [-1]))


(M, K) = map(int, input().split())
if K == 0:
	l = []
	for i in range(2 ** M):
		l += [i, i]
	print(*l)
elif M == 0 or M == 1:
	print(-1)
elif 1 <= K < 2 ** M:
	l = []
	for i in range(2 ** M):
		if i != K:
			l += [i]
	l += [K]
	for i in range(2 ** M)[::-1]:
		if i != K:
			l += [i]
	l += [K]
	print(*l)
else:
	print(-1)


(m, k) = map(int, input().split())
x = list(range(2 ** m))
print(*(x[::-1] + x if k == 0 else x[:k:-1] + x[k - 1::-1] + [k] + x[:k] + x[k + 1:] + [k] if k < 2 ** m and m > 1 else [-1]))


(M, K) = map(int, input().split())
ans = [-1]
if M == 1:
	if K == 0:
		ans = [0, 0, 1, 1]
elif K < 2 ** M:
	b = [i for i in range(2 ** M) if i != K]
	ans = b + [K] + b[::-1] + [K]
print(*ans)


import sys
input = sys.stdin.readline
from functools import reduce
from operator import xor

def read():
	(M, K) = list(map(int, input().strip().split()))
	return (M, K)

def solve(M, K):
	seq = [str(0) for i in range(2 ** (M + 1))]
	if K == 0:
		for i in range(2 ** M):
			seq[2 * i] = str(i)
			seq[2 * i + 1] = str(i)
	else:
		if K >= 2 ** M:
			return -1
		S = [a for a in range(2 ** M) if a not in (0, K)]
		if len(S) == 0 or reduce(xor, S) != K:
			return -1
		j = 0
		for i in range(2 ** M - 2):
			j += 1
			if j == K:
				j += 1
			seq[i + 1] = str(j)
			seq[2 ** (M + 1) - i - 1] = str(j)
		seq[0] = str(K)
		seq[2 ** M] = str(K)
	return ' '.join(seq)

def __starting_point():
	inputs = read()
	print(solve(*inputs))
__starting_point()


(M, K) = (int(i) for i in input().split())
if M == 1:
	if K == 0:
		print('0 0 1 1')
	else:
		print('-1')
else:
	N = 2 ** M
	if K >= N:
		print('-1')
	elif K == 0:
		l = list(range(N))
		ll = l + l[::-1]
		ll = [str(a) for a in ll]
		print(' '.join(ll))
	else:
		l = list(range(N))
		l = l[:K] + l[K + 1:]
		ll = [0, K] + l + [K] + l[::-1][:-1]
		ll = [str(a) for a in ll]
		print(' '.join(ll))


(m, k) = list(map(int, input().split()))
if 2 ** m <= k or m * k == 1:
	print(-1)
elif m == 1 and k == 0:
	print('0 0 1 1')
else:
	ans = [-1 for i in range(2 ** (m + 1))]
	sta = 2 ** m - 1
	cnt = 0
	for i in range(1, 2 ** m):
		if cnt == k:
			cnt += 1
		ans[sta + i] = cnt
		ans[sta - i] = cnt
		cnt += 1
	ans[sta] = k
	ans[-1] = k
	print(' '.join([str(i) for i in ans]))


(m, k) = map(int, input().split())
if k >= 2 ** m or m == k == 1:
	print(-1)
elif m == 1:
	print('1 1 0 0')
else:
	l = list(range(k)) + list(range(k + 1, 2 ** m))
	print(*l + [k] + l[::-1] + [k])


(M, K) = map(int, input().split())
num = 2 ** (M + 1)
if K >= num // 2 or (M == 1 and K == 1):
	ans = [-1]
elif M == 1 and K == 0:
	ans = [0, 0, 1, 1]
else:
	ans = [0] * num
	for i in range(2 ** M):
		if i == K:
			continue
		ans[i - (i > K)] = i
		ans[num - 2 - i + (i > K)] = i
	ans[num // 2 - 1] = K
	ans[-1] = K
print(*ans)


def power(n, m):
	ret = 1
	for i in range(m):
		ret *= n
	return ret
(M, K) = map(int, input().split())
if K >= power(2, M):
	print(-1)
elif M == 0:
	print(0, 0)
elif M == 1:
	if K == 1:
		print(-1)
	else:
		print(0, 0, 1, 1)
else:
	ans = []
	N = power(2, M)
	if K % 2 == 1:
		ans.append(K)
		ans.append(K - 1)
		for i in range(0, N):
			if i == K or i == K - 1:
				continue
			ans.append(i)
		ans.append(K)
		for i in range(N - 1, -1, -1):
			if i == K or i == K - 1:
				continue
			ans.append(i)
		ans.append(K - 1)
	else:
		ans.append(K)
		ans.append(K + 1)
		for i in range(0, N):
			if i == K or i == K + 1:
				continue
			ans.append(i)
		ans.append(K)
		for i in range(N - 1, -1, -1):
			if i == K or i == K + 1:
				continue
			ans.append(i)
		ans.append(K + 1)
	print(' '.join(map(str, ans)))


(m, k) = map(int, input().split())
if 2 ** m <= k:
	print(-1)
	return
elif m == 0 and k == 0:
	print('0 0')
	return
elif m == 1 and k == 1:
	print(-1)
	return
elif m == 1 and k == 0:
	print('1 1 0 0')
	return
l = [i for i in range(2 ** m) if i != k]
rev_l = sorted(l, reverse=True)
ans = l + [k] + rev_l + [k]
print(' '.join(map(str, ans)))


import sys
(M, K) = map(int, input().split())
if M == 0:
	if K == 0:
		print(*[0, 0])
	else:
		print(-1)
	return
if M == 1:
	if K == 0:
		print(*[0, 1, 1, 0])
	else:
		print(-1)
	return
N = 2 ** M
if K >= N:
	print(-1)
	return
ans = []
for i in range(N):
	if i != K:
		ans.append(i)
ans.append(K)
for i in range(N - 1, -1, -1):
	if i != K:
		ans.append(i)
ans.append(K)
print(*ans)


(m, k) = list(map(int, input().split()))
if m == 0:
	if k == 0:
		print('0 0')
	else:
		print('-1')
elif m == 1:
	if k == 0:
		print('0 0 1 1')
	elif k >= 1:
		print('-1')
elif k < 2 ** m:
	l = []
	for i in range(2 ** m):
		if i != k:
			l.append(i)
	ans = l + [k] + l[::-1] + [k]
	ans2 = ''
	for a in ans:
		ans2 += str(a) + ' '
	print(ans2[:-1])
else:
	print(-1)


(m, k) = map(int, input().split())
if k > 2 ** m - 1:
	print(-1)
elif m == 1 and k == 1:
	print(-1)
else:
	(a, b) = (0, 0)
	i = 0
	while k > 0:
		if k % 2:
			a += 2 ** i
		k //= 2
		i += 1
	if a == 0:
		ans = []
		for i in range(2 ** m):
			ans.append(i)
			ans.append(i)
	else:
		ans = [0] * 2 ** (m + 1)
		ans[2 ** m - 1] = b
		ans[-1] = a
		ans[2 ** m] = a
		ans[0] = b
		s = {a, b}
		idx = 0
		for i in range(2 ** m):
			if i not in s:
				ans[idx + 1] = i
				ans[-2 - idx] = i
				idx += 1
	print(*ans)


MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1, 0, 1, 0)
dx = (0, 1, 0, -1)

def main():
	(m, k) = map(int, input().split())
	if k >= pow(2, m):
		print(-1)
		return
	if m == 1:
		if k == 1:
			print(-1)
		else:
			print('{0} {0} {1} {1}'.format(0, 1))
		return
	ans = [k]
	ans2 = [k]
	lim = pow(2, m)
	for i in range(lim):
		if i != k:
			ans.append(i)
		if lim - i - 1 != k:
			ans2.append(lim - i - 1)
	ans += ans2
	print(*ans)

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline

def main():
	(M, K) = list(map(int, input().split()))
	if K >= 2 ** M:
		print(-1)
		return
	if M == 1:
		if K == 0:
			print((0, 0, 1, 1))
		else:
			print(-1)
		return
	A = list(range(2 ** M))
	B = list(reversed(list(range(2 ** M))))
	A.remove(K)
	B.remove(K)
	ans = A + [K] + B + [K]
	print(' '.join(map(str, ans)))

def __starting_point():
	main()
__starting_point()


(M, K) = list(map(int, input().split()))
if M <= 1:
	if K > 0:
		print(-1)
		return
	elif M == 1:
		print(' '.join(['0', '0', '1', '1']))
		return
	else:
		print('0 0')
		return
elif K >= 2 ** M:
	print(-1)
	return
ans = [str(K)]
exclude_k = [str(i) for i in range(2 ** M) if i != K]
ans.extend(exclude_k)
ans.append(str(K))
ans.extend(exclude_k[::-1])
print(' '.join(ans))


(m, k) = map(int, input().split())
x = [*range(1 << m)]
print(*(([-1], [k] + x[k + 1:] + x[:k] + [k] + x[k - 1::-1] + x[:k:-1])[k < 1 << m > 2], x + x[::-1])[k < 1])


(m, k) = map(int, input().split())
if m == 1:
	if k != 0:
		print(-1)
	else:
		print(0, 0, 1, 1)
	return
elif 2 ** m <= k:
	print(-1)
	return
b = []
for i in range(2 ** m):
	if i != k:
		b.append(i)
c = b[::-1]
d = b + [k] + c + [k]
print(*d)


(M, K) = map(int, input().split())

def binary_digits(n):
	cnt = 0
	while n != 0:
		cnt += 1
		n //= 2
	return cnt
if binary_digits(K) > M:
	print(-1)
elif M == 1:
	if K == 1:
		print(-1)
	elif K == 0:
		print(0, 0, 1, 1)
else:
	b = 2 ** (M + 1)
	if K == 0:
		for i in range(b):
			if i != b - 1:
				print(i // 2, end=' ')
			else:
				print(i // 2)
	else:
		A = [0 for i in range(b)]
		(A[1], A[b // 2 + 1]) = (K, K)
		p = 1
		for i in range(1, b // 2):
			if i != K:
				(A[b // 2 - p + 1], A[b // 2 + p + 1]) = (i, i)
				p += 1
		for i in range(b):
			if i != b - 1:
				print(A[i], end=' ')
			else:
				print(A[i])


import itertools
(M, K) = map(int, input().split())
if M == 1 and K == 1:
	print(-1)
elif K == 0:
	ans_list = []
	for i in range(2 ** M):
		ans_list.extend([i, i])
	print(*ans_list)
elif K < 2 ** M:
	ans_list = []
	for i in range(K + 1):
		ans_list.append(i)
	for i in reversed(range(K)):
		ans_list.append(i)
	for i in reversed(range(K, 2 ** M)):
		ans_list.append(i)
	for i in range(K + 1, 2 ** M):
		ans_list.append(i)
	print(*ans_list)
else:
	print(-1)


(m, k) = [int(x) for x in input().split()]
if m == 1:
	if k == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
elif k < 1 << m:
	a = [str(i) for i in range(1 << m) if i != k]
	print(' '.join(a), k, ' '.join(reversed(a)), k)
else:
	print(-1)


(M, K) = map(int, input().split())
if M == 0 and K == 0:
	ans = [0, 0]
elif M == 1:
	if K == 0:
		ans = [0, 0, 1, 1]
	else:
		ans = [-1]
elif K >= 2 ** M:
	ans = [-1]
else:
	ans = []
	for i in range(2 ** M):
		if i != K:
			ans.append(i)
	ans.append(K)
	for j in range(2 ** M - 1, -1, -1):
		if j != K:
			ans.append(j)
	ans.append(K)
for i in ans:
	print(i, end=' ')


(M, K) = list(map(int, input().split()))
if M < 2:
	if K != 0:
		print(-1)
	else:
		anss = []
		for A in range(2 ** M):
			anss += [A, A]
		print(' '.join(map(str, anss)))
elif K > 2 ** M - 1:
	print(-1)
else:
	anss = []
	for A in range(2 ** M):
		if A == K:
			continue
		anss.append(A)
	anss = anss + [K] + anss[::-1] + [K]
	print(' '.join(map(str, anss)))


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 7)
	from collections import Counter, deque
	from itertools import combinations, permutations, accumulate, groupby, product
	from bisect import bisect_left, bisect_right
	from heapq import heapify, heappop, heappush
	import math
	(m, k) = map(int, input().split())
	if m == 0:
		if k == 0:
			print(0, 0)
		else:
			print(-1)
	elif m == 1:
		if k == 0:
			print(0, 0, 1, 1)
		else:
			print(-1)
	elif k >= 2 ** m:
		print(-1)
	else:
		res = []
		for i in range(2 ** m):
			if i != 0 and i != k:
				res.append(i)
		if k == 0:
			res = res + [0] + res[::-1] + [0]
		else:
			res = res + [0, k] + res[::-1] + [k, 0]
		print(*res)

def __starting_point():
	main()
__starting_point()


(m, k) = map(int, input().split())
ret = []
if k >= 2 ** m or (m == 1 and k == 1):
	ret.append(-1)
elif m == 1:
	ret = [0, 0, 1, 1]
else:
	ret.append(k)
	for i in range(2 ** m):
		if i != k:
			ret.append(i)
	ret.append(k)
	for i in range(2 ** m - 1, -1, -1):
		if i != k:
			ret.append(i)
print(' '.join(map(str, ret)))


(M, K) = map(int, input().split())
if K >= 2 ** M:
	print(-1)
	return
elif M == 0:
	print('0 0')
elif M == 1:
	if K == 0:
		print('0 0 1 1')
	else:
		print(-1)
else:
	A = [i for i in range(2 ** M) if i != K]
	B = A[::-1]
	for a in A:
		print(a, end=' ')
	print(K, end=' ')
	for b in B:
		print(b, end=' ')
	print(K)


(M, K) = map(int, input().split())
if K >= 2 ** M:
	print(-1)
elif M == 0:
	if K == 0:
		print(0, 0)
	else:
		print(-1)
elif M == 1:
	if K == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
else:
	b = [str(i) for i in range(2 ** M) if not i == K]
	c = [str(i) for i in range(2 ** M - 1, -1, -1) if not i == K]
	ans = b + [str(K)] + c + [str(K)]
	print(' '.join(ans))


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float('inf')
(M, K) = map(int, input().split())
if M == 1:
	if K == 0:
		ans = [0, 0, 1, 1]
		print(*ans)
	else:
		print(-1)
elif K > 2 ** M - 1:
	print(-1)
elif K == 0:
	ans = []
	for i in range(2 ** M):
		ans.append(i)
		ans.append(i)
	print(*ans)
else:
	ans = deque([K])
	for i in range(2 ** M):
		if i == K:
			continue
		ans.append(i)
		ans.appendleft(i)
	ans.append(K)
	print(*ans)


import sys
(M, K) = [int(i) for i in input().split()]
if K >= 2 ** M:
	print(-1)
	return
if M == 1:
	if K == 0:
		print(*[0, 0, 1, 1])
		return
	else:
		print(-1)
		return
L = []
l = [int(i) for i in range(2 ** M) if i != K]
L.extend(l)
L.append(K)
L.extend(l[::-1])
L.append(K)
print(*L)


(m, k) = map(int, input().split())
if m * k == 1:
	print(-1)
	return
if k == 0:
	ans = []
	for i in range(2 ** m):
		ans.append(i)
		ans.append(i)
	print(*ans)
	return
if 2 ** m <= k:
	print(-1)
else:
	ans = [k]
	chk = list(range(2 ** m))
	chk.remove(k)
	ans = ans + chk + [k] + chk[::-1]
	print(' '.join(map(str, ans)))


(M, K) = map(int, input().split())
if M == 0:
	if K == 0:
		print(0, 0)
	else:
		print(-1)
	return
if M == 1:
	if K == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
	return
N = 2 ** M
if N <= K:
	print(-1)
	return
ans = []
ans.append(K)
for i in range(N):
	if i == K:
		continue
	ans.append(i)
ans.append(K)
for i in range(N - 1, -1, -1):
	if i == K:
		continue
	ans.append(i)
for i in ans:
	print(i, end=' ')


import sys
(m, k) = map(int, input().strip().split())
max_num = 2 ** m
if k >= max_num:
	print(-1)
	return
if m == 0:
	print('0 0')
	return
if m == 1:
	if k == 0:
		print('0 0 1 1')
	else:
		print('-1')
	return
res = []
for i in range(max_num):
	if i == k:
		continue
	res.append(i)
res.append(k)
for i in range(max_num):
	j = max_num - i - 1
	if j == k:
		continue
	res.append(j)
res.append(k)
for i in range(2 ** (m + 1)):
	print(res[i], end=' ')


(m, k) = map(int, input().split())
if k >= 2 ** m:
	print(-1)
	return
if m == 1:
	if k == 0:
		print(0, 0, 1, 1)
	if k == 1:
		print(-1)
	return
base = [i for i in range(2 ** m) if i != k]
ans = base + [k] + base[::-1] + [k]
print(*ans)


def main():
	(M, K) = list(map(int, input().split()))
	if M == 1:
		if K == 0:
			print('0 0 1 1')
			return
		if K == 1:
			print('-1')
			return
	if 2 ** M - 1 < K:
		print('-1')
		return
	l = [i for i in range(K)] + [i for i in range(K + 1, 2 ** M)] + [K] + [i for i in reversed(list(range(K + 1, 2 ** M)))] + [i for i in reversed(list(range(K)))] + [K]
	print(' '.join((str(i) for i in l)))
main()


from collections import deque
(m, k) = map(int, input().split())
if k >= pow(2, m):
	print(-1)
elif m == 0:
	print(0, 0)
elif m == 1:
	if k == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
else:
	ans = deque()
	ans.append(k)
	for i in range(pow(2, m)):
		if i != k:
			ans.append(i)
			ans.appendleft(i)
	ans.append(k)
	print(' '.join(map(str, ans)))


(M, K) = map(int, input().split())
if M == 1:
	if K == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
elif K >= 2 ** M:
	print(-1)
else:
	ls = list(range(2 ** M))
	ls.remove(K)
	ans = [K] + ls + [K] + ls[::-1]
	print(' '.join(map(str, ans)))


def test(m):
	t = [i for i in range(2 ** m)]
	for i in range(2 ** m):
		t.append(i)
	t.sort()
	st = set()
	bt = set()
	from itertools import permutations
	for v in permutations(t):
		taget = v[0]
		x = 0
		idx = 1
		while idx < len(v) and v[idx] != taget:
			x = x ^ v[idx]
			idx += 1
		if x in st or x in bt:
			continue
		f = True
		for i in range(1, len(v)):
			g = False
			y = 0
			idx = i + 1
			while idx < len(v):
				if v[i] == v[idx]:
					g = True
					break
				y = y ^ v[idx]
				idx += 1
			if g:
				if y != x:
					f = False
					break
		if f:
			st.add(x)
			print(x, v)

def main():
	(m, k) = map(int, input().split())
	x = 0
	for i in range(2 ** m):
		if i == k:
			continue
		x ^= i
	if k == 0:
		for i in range(2 ** m):
			print(i, i, end=' ')
	elif x == k:
		for i in range(2 ** m):
			if i == k:
				continue
			print(i, end=' ')
		print(k, end=' ')
		for i in reversed(range(2 ** m)):
			if i == k:
				continue
			print(i, end=' ')
		print(k)
	else:
		print(-1)

def __starting_point():
	main()
__starting_point()


(m, k) = map(int, input().split())
if m == 0:
	if k == 0:
		print(0, 0)
	else:
		print(-1)
elif m == 1:
	if k == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
else:
	if k >= 2 ** m:
		print(-1)
		return
	res = []
	for i in range(2 ** m):
		if i == k:
			continue
		res.append(i)
	ans = [k] + res + [k] + res[::-1]
	print(*ans)


def main():
	(M, K) = map(int, input().split())
	if K == 0:
		ans = []
		for i in range(2 ** M):
			ans.extend([i, i])
		print(*ans)
		return 0
	if 2 ** M <= K:
		print(-1)
		return 0
	if M == 1:
		if K == 1:
			print(-1)
			return 0
	ans = [str(x) for x in range(2 ** M) if x != K]
	ans_b = [str(x) for x in range(2 ** M - 1, -1, -1) if x != K]
	print(str(K) + ' ' + ' '.join(ans) + ' ' + str(K) + ' ' + ' '.join(ans_b))
main()


import bisect
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

class v:

	def __init__(self, f):
		self.f = f
		self.v = None

	def __str__(self):
		return str(self.v)

	def ud(self, n):
		if self.v is None:
			self.v = n
		else:
			self.v = self.f(self.v, n)

def read_values():
	return list(map(int, input().split()))

def read_list():
	return list(read_values())

def main():
	(M, K) = read_values()
	if K >= 2 ** M:
		print(-1)
		return
	if M == 1:
		print('0 0 1 1' if K == 0 else -1)
		return
	X = [str(i) for i in range(2 ** M) if i != K]
	res = X + [str(K)] + X[::-1] + [str(K)]
	print(' '.join(res))

def __starting_point():
	main()
__starting_point()


(M, K) = map(int, input().split())
if M == 0:
	if K == 0:
		print(0, 0)
	else:
		print(-1)
elif M == 1:
	if K == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
elif K == 0:
	A = [i // 2 for i in range(2 ** (M + 1))]
	print(*A)
elif 0 < K < 2 ** M:
	A = []
	for i in range(K):
		A.append(i)
	for i in range(2 ** M - K - 1):
		A.append(2 ** M - i - 1)
	A.append(0)
	for i in range(2 ** M - K):
		A.append(K + i)
	for i in range(K - 1):
		A.append(K - i - 1)
	A.append(K)
	print(*A)
else:
	print(-1)


import sys
input = sys.stdin.buffer.readline

def main():
	(M, K) = map(int, input().split())
	if M == 0:
		if K == 0:
			print(0, 0)
		else:
			print(-1)
	elif M == 1:
		if K == 0:
			print(0, 0, 1, 1)
		else:
			print(-1)
	elif 2 ** M <= K:
		print(-1)
	else:
		use = [i for i in range(2 ** M)]
		use.pop(K)
		_use = list(reversed(use))
		ans = use + [K] + _use + [K]
		print(*ans)

def __starting_point():
	main()
__starting_point()


(m, k) = map(int, input().split())
if pow(2, m) <= k:
	print(-1)
elif not m == 1:
	ans = [k] * pow(2, m + 1)
	i = 0
	for j in range(pow(2, m) - 1):
		if i == k:
			i += 1
		ans[j] = i
		ans[pow(2, m + 1) - 2 - j] = i
		i += 1
	print(*ans)
elif k == 0:
	print(0, 0, 1, 1)
else:
	print(-1)


(m, k) = map(int, input().split())
if m == 1:
	if k == 0:
		print(0, 0, 1, 1)
	else:
		print(-1)
elif 2 ** m <= k:
	print(-1)
else:
	remain = set(range(2 ** m))
	use = set()
	count = 0
	while k:
		if k & 1:
			remain.remove(2 ** count)
			use.add(2 ** count)
		k >>= 1
		count += 1
	ans = []
	remain = list(remain)
	use = list(use)
	for i in remain:
		ans.append(str(i))
	for i in use:
		ans.append(str(i))
	for i in remain[::-1]:
		ans.append(str(i))
	for i in use[::-1]:
		ans.append(str(i))
	print(' '.join(ans))


(m, k) = map(int, input().split())
v = []
if k == 0:
	for i in range(0, 2 ** m):
		v.append(i)
		v.append(i)
elif k < 2 ** m and m > 1:
	for i in range(0, 2 ** m):
		if i != k:
			v.append(i)
	v.append(k)
	for i in range(2 ** m - 1, -1, -1):
		if i != k:
			v.append(i)
	v.append(k)
if len(v) == 0:
	print(-1)
else:
	for i in range(0, len(v)):
		print(v[i])
		if i == len(v) - 1:
			print('\n')
		else:
			print(' ')


import sys

def solve(M: int, K: int):
	if K >= 1 << M:
		print(-1)
		return
	if M == 1:
		if K == 0:
			print(0, 0, 1, 1)
		else:
			print(-1)
		return
	for i in range(1 << M):
		if i != K:
			print(i, end=' ')
	print(K, end=' ')
	for i in reversed(range(1 << M)):
		if i != K:
			print(i, end=' ')
	print(K)

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	M = int(next(tokens))
	K = int(next(tokens))
	solve(M, K)

def __starting_point():
	main()
__starting_point()


(m, k) = map(int, input().split())
if k <= 2 ** m - 1 and m > 1:
	lists = []
	for i in range(2 ** m - 1, -1, -1):
		if i != k:
			lists.append(i)
	lists.append(k)
	for i in range(2 ** m):
		if i != k:
			lists.append(i)
	lists.append(k)
	print(*lists)
elif k <= 2 ** m - 1 and m == 0:
	print(*[0, 0])
elif k <= 2 ** m - 1 and m == 1:
	if k == 0:
		print(*[0, 0, 1, 1])
	elif k == 1:
		print(-1)
else:
	print(-1)