Problem:
 Score : 600 points    Problem Statement 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 .)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n,k = LI()
    s = input()
    for i in range(k-1):
        print(s[i],end = "")
    print(s[k-1].lower(),end = "")
    for i in range(k,n):
        print(s[i],end = "")
    print()
    return


def B():
    s = S()
    k = int(s[0])*10+int(s[1])
    l = int(s[2])*10+int(s[3])
    if k == 0:
        if l == 0:
            print("NA")
        elif l < 13:
            print("YYMM")
        else:
            print("NA")
    elif k < 13:
        if l == 0:
            print("MMYY")
        elif l < 13:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    else:
        if l == 0:
            print("NA")
        elif l < 13:
            print("YYMM")
        else:
            print("NA")


def C():
    n,k = LI()
    ans = 0
    for i in range(1,n+1):
        l = k/i
        ans += 1/n*1/(2 << max(0,math.ceil(math.log(l,2))))
    print(ans*2)
    return


def D():
    n = I()
    v = [[] for i in range(n)]
    for i in range(n-1):
        x,y,w = LI()
        x -= 1
        y -= 1
        v[x].append((y,w))
        v[y].append((x,w))
    ans = [0 for i in range(n)]
    bfs_map = [1 for i in range(n)]
    bfs_map[0] = 0
    q = deque()
    q.append(0)
    while q:
        x = q.popleft()
        for y,w in v[x]:
            if bfs_map[y]:
                if w%2:
                    ans[y] = ans[x]^1
                else:
                    ans[y] = ans[x]
                bfs_map[y] = 0
                q.append(y)
    for i in ans:
        print(i)
    return


def E():
    def root(x):
        if par[x] == x:
            return par[x]
        par[x] = root(par[x])
        return par[x]
    def same(x,y):
        return root(x) == root(y)
    def unite(x,y):
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1
    n,m = LI()
    par = [i for i in range(n)]
    rank = [0 for i in range(n)]
    for i in range(m):
        x,y,z = LI()
        x -= 1
        y -= 1
        if not same(x,y):
            unite(x,y)
    for i in range(n):
        root(i)
    par = list(set(par))
    print(len(par))
    return


def F():
    m,k = LI()
    l = 1 << m
    if k == 0:
        ans = []
        for i in range(l):
            ans.append(i)
            ans.append(i)
        print(*ans)
    else:
        if m <= 1:
            print(-1)
        else:
            if k >= l:
                print(-1)
            else:
                ans = [0,k,0]
                lis = [i for i in range(1,l)]
                lis.pop(k-1)
                for i in lis[::-1]:
                    ans.append(i)
                ans.append(k)
                for i in lis:
                    ans.append(i)
                print(*ans)
    return


if __name__ == "__main__":
    F()

Solution (Python):
m, k = input().split()
m, k = int(m), int(k)


xx = 0
for i in range(2**m):
    xx = xx ^ i

if k == 0:
    arr = [0] * (2 ** (m+1))
    for i in range(2**m):
        arr[2*i] = i
        arr[2*i+1] = i
    print(" ".join([str(x) for x in arr]))
elif xx != 0 or k >= 2 ** m:
    print(-1)
else:
    arr = [0] * (2 ** (m+1))
    f = (2 ** (m+1))
    arr[0] = k
    arr[f//2] = k
    pt1 = f // 2 - 1
    pt2 = f // 2 + 1
    curr = 0
    for i in range((f - 2) // 2):
        if (curr == k):
            curr += 1
        arr[pt1] = curr
        arr[pt2] = curr
        pt1 -= 1
        pt2 += 1 
        curr += 1
    print(" ".join([str(x) for x in arr]))

Solution (Python):
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')
  else:
    print(-1)
    
else:
  if K >= 2**M:
    print(-1)
  else:
    L = list(range(2**M))
    answer = [K] + L[:K] + L[K+1:2**M] + [K] + (L[:K] + L[K+1:2**M])[::-1]
    print(' '.join([str(a) for a in answer]))

Solution (Python):
m,k = map(int,input().split())
if k == 0:
    l = [i // 2 for i in range(2 ** (m + 1))]
    print(*l)
    exit()

if m == 0:
    if k == 0:
        print(0, 0)
    else:
        print(-1)
    exit()

if m == 1:
    if k == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
    exit()

if not 0 <= k < 2 ** m:
    print(-1)
    exit()

l = [0]
for i in range(2 ** (m - 1) - 1):
    l.append(2 ** (m - 1) - i)
for i in range(2 ** (m - 1)):
    l.append(i + 1)
for i in range(2 ** m):
    if i == 0:
        l.append(0)
    elif i == 2 ** (m - 1):
        l.append(l[i])
    else:
        l.append(l[i] + 2 ** (m - 1) - 1)

if k == 1:
    print(*l)
    exit()

for i in range(len(l)):
    if l[i] == 1:
        l[i] = k
    elif l[i] == k:
        l[i] = 1
print(*l)

Solution (Python):
M, K = map(int, input().split())

if K >= 2 ** M:
    print(-1)
elif K == 0:
    ans = []
    x = range(0, 2 ** M)
    y = range(0, 2 ** M)
    for xx, yy in zip(x, y):
        ans.append(xx)
        ans.append(yy)
    print(*ans)
else:
    t = 0
    for i in range(1, 2 ** M):
        if i == K: continue
        t ^= i
    if t == K:
        x = [i for i in range(0, 2 ** M) if i != K]
        ans = [K] + x + [K] + list(reversed(x))
        print(*ans)
    else:
        print(-1)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

m,k = li()

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:
    xor = 0
    cur = []
    for i in range(pow(2,m)):
        if i == k:
            continue

        else:
            xor ^= i
            cur.append(i)

    if xor == k:
        ans = [k] + cur[::-1] + [k] + cur
        print(*ans)

    else:
        print(-1)

Solution (Python):

import sys


def solve(M: int, K: int):
    n = 2 ** M
    if n <= K or (M == 1 and K == 1):
        print(-1)
        return -1
    if M == 1 and K == 0:
        print('0 0 1 1')
        return
    ret = []
    for i in range(n):
        if i != K:
            ret.append(i)
    ret.append(K)
    for i in range(n - 1, -1, -1):
        if i != K:
            ret.append(i)
    ret.append(K)
    print(' '.join([str(i) for i in ret]))
    return


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)

if __name__ == '__main__':
    main()

Solution (Python):
M, K = map(int, input().split())

if K == 0:
    print(*[i//2 for i in range(2**(M+1))])
elif M == 1:
    print(-1)
elif K < 2**M:
    X = [i for i in range(1, 2**M) if i != K]
    print(*([0] + X + [0] + [K] + X[::-1] + [K]))
else:
    print(-1)

Solution (Python):
M, K = map(int, input().split())

if K >= 2**M or (M == 1 and K == 1):
    ans = -1
elif K == 0:
    a = []
    for i in range(2**M):
        a.append(i)
        a.append(i)
    ans = ' '.join(map(str, a))
else:
    a = [0, K, 0]
    for i in range(1, 2**M):
        if i != K:
            a.append(i)
    a.append(K)
    for i in range(2**M - 1, 0, -1):
        if i != K:
            a.append(i)
    ans = ' '.join(map(str, a))

print(ans)

Solution (Python):
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==0:
        ans=[str(i//2) for i in range(2**(M+1))]
        print(" ".join(ans))
    elif 1<=K<2**M:
        L=[0 for i in range(2**M)]
        X=[]
        for i in range(2**M):
            if L[i]==0:
                X.append((i,i^K))
                L[i]=1
                L[i^K]=1
        st=[]
        for i in range(2**(M-2)):
            a,b=X[2*i]
            c,d=X[2*i+1]
            tmp=[a,c,d,a,b,d,c,b]
            st.append(" ".join([str(i) for i in tmp]))
        print(" ".join(st))
    else:
        print(-1)

Solution (Python):
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==0:
        ans=[str(i//2) for i in range(2**(M+1))]
        print(" ".join(ans))
    elif 1<=K<2**M:
        L=[0 for i in range(2**M)]
        X=[]
        for i in range(2**M):
            if L[i]==0:
                X.append((i,i^K))
                L[i]=1
                L[i^K]=1
        st=[]
        for i in range(2**(M-2)):
            a,b=X[2*i]
            c,d=X[2*i+1]
            tmp=[a,c,d,a,b,d,c,b]
            st.append(" ".join([str(i) for i in tmp]))
        print(" ".join(st))
    else:
        print(-1)

Solution (Python):
import sys
M,K=map(int,input().split())

if M==0:
    if K==0:
        print(0,0)
    else:
        print(-1)
    sys.exit()

if M==1:
    if K==0:
        print(0,0,1,1)
    else:
        print(-1)
    sys.exit()

if K==0:
    ANS=[]
    for i in range(2**M):
        ANS.append(i)
        ANS.append(i)
    print(*ANS)
    sys.exit()

if not(1<=K<2**M):
    print(-1)
    sys.exit()

LIST=[]

for i in range(2**M):
    if K==i:
        continue
    LIST.append(i)

ANS=[K]+LIST[::-1]+[K]+LIST
print(*ANS)

Solution (Python):
M, K = map(int, input().split())
if M==1:
    if K==0:
        print("0 0 1 1")
    else:
        print(-1)
else:
    if K < 1<<M:
        A = []
        for i in range(1<<M):
            if i != K:
                A.append(i)
        print(*A, end=" ")
        print(K, end=" ")
        print(*A[::-1], end=" ")
        print(K)
    else:
        print(-1)

Solution (Python):


from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

M, K = map(int, raw_input().split())
if M == 1 and K == 1:
    print -1
    exit()
if M == 1 and K == 0:
    print "0 0 1 1"
    exit()
if K >= 2 ** M:
    print -1
    exit()
ls = range(K) + range(K + 1, 2 ** M)
ls2 = list(ls[::-1])
ans = ls2 + [K] + ls + [K]
print " ".join(map(str, ans))

Solution (Python):
m, k = map(int, input().split())

if m == 1:
    if k == 0:
        print(*[0, 0, 1, 1])
    else:
        print(-1)
    exit()

n = 2 ** m
if k >= n:
    print(-1)
    exit()

ans = [0] * (n * 2)
i = 1
for v in range(n):
    if v == k:
        ans[0] = ans[n] = v
        continue
    ans[i] = ans[2 * n - i] = v
    i += 1
print(*ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)


def main():
    m,k = LI()
    if m == 1:
        if k == 0:
            return '1 1 0 0'
        return -1

    t = pow(2,m)
    if k >= t:
        return -1
    a = list(range(t))
    r = a[:k] + a[k+1:] +[k] + a[k+1:][::-1] + a[:k][::-1] + [k]

    return ' '.join(map(str, r))


print(main())