Buggy python submission (verdict: Runtime Error):
from collections import deque

m, k = [int(i) for i in input().split()]

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

if k == 0:
    q = deque([])
    for i in range(2 ** m):
        q.append(i)
        q.appendleft(i)
    print(*q)
    exit()


S = set(i for i in range(2 ** m))

q = deque([0, k])
S.remove(0)
S.remove(k)

for i in range(m):
    if (k >> i) & 1:
        t = 1 << i
        if not t in:
            if t + 3 in S:
                t += 3
                q.append(3)
                q.appendleft(3)
                S.remove(3)
            else:
                print(-1)
                exit()
        q.append(t)
        q.appendleft(t)
        S.remove(t)

q.appendleft(0)
q.append(k)

for s in S:
    q.appendleft(s)
    q.append(s)

print(*q)


Fixed submission:
from collections import deque

m, k = [int(i) for i in input().split()]

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

if k == 0:
    q = deque([])
    for i in range(2 ** m):
        q.append(i)
        q.appendleft(i)
    print(*q)
    exit()

if m == 1 and k == 1:
    print(-1)
    exit()

S = set(i for i in range(2 ** m))

q = deque([0, k])
S.remove(0)
S.remove(k)

for s in S:
    q.appendleft(s)
    q.append(s)

q.appendleft(0)
q.append(k)

print(*q)

Buggy python submission (verdict: Runtime Error):
from collections import deque

m, k = [int(i) for i in input().split()]

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

if k == 0:
    q = deque([])
    for i in range(2 ** m):
        q.append(i)
        q.appendleft(i)
    print(*q)
    exit()


S = set(i for i in range(2 ** m))

q = deque([0, k])
S.remove(0)
S.remove(k)

for i in range(m):
    if (k >> i) & 1:
        t = 1 << i
        if not t in:
            if t + 1 in S:
                t += 1
            else:
                print(-1)
                exit()
        q.append(t)
        q.appendleft(t)
        S.remove(t)

q.appendleft(0)
q.append(k)

for s in S:
    q.appendleft(s)
    q.append(s)

print(*q)


Fixed submission:
from collections import deque

m, k = [int(i) for i in input().split()]

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

if k == 0:
    q = deque([])
    for i in range(2 ** m):
        q.append(i)
        q.appendleft(i)
    print(*q)
    exit()

if m == 1 and k == 1:
    print(-1)
    exit()

S = set(i for i in range(2 ** m))

q = deque([0, k])
S.remove(0)
S.remove(k)

for s in S:
    q.appendleft(s)
    q.append(s)

q.appendleft(0)
q.append(k)

print(*q)

Buggy python submission (verdict: Runtime Error):
from collections import deque

m, k = [int(i) for i in input().split()]

if k == 0:
    q = deque([])
    for i in range(2 ** m):
        q.append(i)
        q.appendleft(i)
    print(*q)
    exit()


S = set(i for i in range(2 ** m))

q = deque([0, k])
S.remove(0)
S.remove(k)

for i in range(m):
    if (k >> i) & 1:
        if not 1 << i in S:
            print(-1)
            exit()
        q.append(1 << i)
        q.appendleft(1 << i)
        S.remove(1 << i)

q.appendleft(0)
q.append(k)

for s in S:
    q.appendleft(s)
    q.append(s)

print(*q)

Fixed submission:
from collections import deque

m, k = [int(i) for i in input().split()]

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

if k == 0:
    q = deque([])
    for i in range(2 ** m):
        q.append(i)
        q.appendleft(i)
    print(*q)
    exit()

if m == 1 and k == 1:
    print(-1)
    exit()

S = set(i for i in range(2 ** m))

q = deque([0, k])
S.remove(0)
S.remove(k)

for s in S:
    q.appendleft(s)
    q.append(s)

q.appendleft(0)
q.append(k)

print(*q)

Buggy python submission (verdict: Runtime Error):
from collections import deque

m, k = [int(i) for i in input().split()]

if k == 0:
    q = deque([])
    for i in range(2 ** m):
        q.append(i)
        q.appendleft(i)
    print(*q)
    exit()


S = set(i for i in range(2 ** m))

q = deque([0, k])
S.remove(0)
S.remove(k)

for i in range(m):
    if (k >> i) & 1:
        if not 1 << i in S:
            print(-1)
            exit()
        q.append(1 << i)
        q.appendleft(1 << i)
        S.remove(1 << i)

q.appendleft(0)
q.append(k)

for s in S:
    q.appendleft(s)
    q.append(s)

print(*q)

Fixed submission:
from collections import deque

m, k = [int(i) for i in input().split()]

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

if k == 0:
    q = deque([])
    for i in range(2 ** m):
        q.append(i)
        q.appendleft(i)
    print(*q)
    exit()

if m == 1 and k == 1:
    print(-1)
    exit()

S = set(i for i in range(2 ** m))

q = deque([0, k])
S.remove(0)
S.remove(k)

for s in S:
    q.appendleft(s)
    q.append(s)

q.appendleft(0)
q.append(k)

print(*q)