Given two integers $n$ and $x$, construct an array that satisfies the following conditions:   for any element $a_i$ in the array, $1 \le a_i<2^n$;  there is no non-empty subsegment with bitwise XOR equal to $0$ or $x$,  its length $l$ should be maximized. 

A sequence $b$ is a subsegment of a sequence $a$ if $b$ can be obtained from $a$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.


-----Input-----

The only line contains two integers $n$ and $x$ ($1 \le n \le 18$, $1 \le x<2^{18}$).


-----Output-----

The first line should contain the length of the array $l$.

If $l$ is positive, the second line should contain $l$ space-separated integers $a_1$, $a_2$, $\dots$, $a_l$ ($1 \le a_i < 2^n$) — the elements of the array $a$.

If there are multiple solutions, print any of them.


-----Examples-----
Input
3 5

Output
3
6 1 3
Input
2 4

Output
3
1 3 1 
Input
1 1

Output
0



-----Note-----

In the first example, the bitwise XOR of the subsegments are $\{6,7,4,1,2,3\}$.

Source: codeforces | Difficulty: HARD
Tags: Bit manipulation

Constructive algorithms


Solutions:
(n, x) = map(int, input().split())
nn = 2 ** n
if x >= nn:
	x = 0
ans = []
for i in range(n):
	oks = [True] * nn
	oks[x] = False
	cur = 0
	for j in ans[::-1]:
		cur ^= j
		oks[cur] = False
		oks[cur ^ x] = False
	try:
		a = next((j for (j, ok) in enumerate(oks[1:], 1) if ok))
	except StopIteration:
		break
	ans = [*ans, a, *ans]
print(len(ans))
if ans:
	print(' '.join(map(str, ans)))


(n, x) = map(int, input().split())
m = 2 ** n
a = [0] * 2 ** 18
b = []
for i in range(m):
	if a[i] == 0:
		a[i] = 1
		a[i ^ x] = 1
		b.append(i)
print(len(b) - 1)
for i in range(1, len(b)):
	print(b[i] ^ b[i - 1], end=' ')


(n, x) = map(int, input().split())
t = 2 ** n
ans = [0]
if x >= t:
	ans = [*range(t)]
else:
	c = set([0])
	for i in range(1, t):
		if i ^ x in c:
			continue
		ans.append(i)
		c.add(i)
print(len(ans) - 1)
print(*[ans[i] ^ ans[i - 1] for i in range(1, len(ans))])


(n, x) = map(int, input().split())
d = {}
for i in range(2 ** n):
	if not d.get(i, False):
		d[i ^ x] = 1
k = 0
print(len(d) - 1)
for i in range(1, 2 ** n):
	if i not in d:
		print(i ^ k, end=' ')
		k = i


(n, x) = map(int, input().split())
a = [True for i in range(pow(2, n))]
check = []
if x < pow(2, n):
	a[x] = False
for i in range(1, pow(2, n)):
	if a[i] == True:
		check.append(i)
		if x ^ i < pow(2, n):
			a[x ^ i] = False
print(len(check))
if len(check) == 1:
	print(check[0])
elif len(check) > 1:
	print(check[0], end=' ')
	for i in range(1, len(check)):
		print(check[i - 1] ^ check[i], end=' ')


def main():
	(N, X) = map(int, input().split())
	L = 2 ** N - 1
	if X <= L:
		P = [0]
		checked = [False] * (L + 1)
		checked[0] = True
		for n in range(1, L + 1):
			inv = n ^ X
			if not checked[inv]:
				P.append(n)
			checked[n] = True
			checked[inv] = True
	else:
		P = [0]
		for n in range(1, L + 1):
			P.append(n)
	ans = []
	for i in range(len(P) - 1):
		ans.append(P[i + 1] ^ P[i])
	if not ans:
		print(0)
	else:
		print(len(ans))
		print(' '.join([str(a) for a in ans]))
main()


(N, X) = map(int, input().split())
if X == 0 or X >= 2 ** N:
	A = [a for a in range(N)]
else:
	for i in range(N):
		if 1 << i & X:
			A = [a for a in range(N) if a != i]
			break

def calc(B):
	if B:
		b = B[-1]
		t = calc(B[:-1])
		return t + [1 << b] + t
	return []
ca = calc(A)
print(len(ca))
if len(ca):
	print(*ca)


(n, x) = map(int, input().split())
if x >= 2 ** n:
	print(2 ** n - 1)
	print(*[t ^ t + 1 for t in range(2 ** n - 1)])
else:
	used = [False] * 2 ** n
	r = [0]
	used[0] = True
	used[x] = True
	for i in range(1, 2 ** n):
		if not used[i]:
			used[i] = used[i ^ x] = True
			r.append(i)
	print(len(r) - 1)
	for i in range(len(r) - 1):
		print(r[i] ^ r[i + 1], end=' ')


(n, x) = map(int, input().split())
if x >= 2 ** n:
	print(2 ** n - 1)
	print(*[1] + [i ^ i + 1 for i in range(1, 2 ** n - 1)])
else:
	print(2 ** (n - 1) - 1)
	if n == 1:
		exit()
	a = []
	bad = [0] * 2 ** n
	(bad[0], bad[x]) = (1, 1)
	for i in range(2 ** n):
		if bad[i] == 0:
			a.append(i)
			bad[i] = 1
			bad[i ^ x] = 1
	print(*[a[0]] + [a[i] ^ a[i + 1] for i in range(len(a) - 1)])


import sys
input = sys.stdin.readline
(n, x) = list(map(int, input().split()))
if n == x == 1:
	print(0)
	return
ANS = []
for i in range(n):
	if i + 1 == x.bit_length():
		continue
	ANS = ANS + [1 << i] + ANS
print(len(ANS))
print(*ANS)


v = [0]
(n, x) = map(int, input().split())
e = [0] * (1 << 18)
e[0] = 1
for i in range(1, 1 << n):
	if e[x ^ i] == 1:
		continue
	e[i] = 1
	v.append(i)
print(len(v) - 1)
print(*[v[i] ^ v[i - 1] for i in range(1, len(v))])


(n, x) = map(int, input().split())
d = {}
N = 2 ** n
d[0] = 1
b = [0]
for i in range(1, N):
	if i ^ x in d:
		continue
	else:
		d[i] = 1
		b.append(i)
ans = []
for i in range(1, len(b)):
	ans.append(b[i] ^ b[i - 1])
print(len(ans))
print(*ans)


(n, x) = map(int, input().split())
markings = [0 for i in range(2 ** n - 1)]
for i in range(1, 2 ** n):
	if markings[i - 1] == 0 and x ^ i < 2 ** n and (i != x):
		markings[(x ^ i) - 1] = 1
if x < 2 ** n:
	markings[x - 1] = 1
arr = []
for i in range(2 ** n - 1):
	if markings[i] == 0:
		arr.append(i + 1)
print(len(arr))
if len(arr) > 0:
	print(arr[0], end=' ')
	for i in range(1, len(arr)):
		print(arr[i] ^ arr[i - 1], end=' ')
	print('')


(n, x) = list(map(int, input().split()))
a = []
d = {0: True}
d1 = [0]
if x < 1 << n:
	for t in range(1, 1 << n):
		if not d.get(t ^ x, False):
			a.append(t ^ d1[-1])
			d[t] = True
			d1.append(t)
	print(len(a))
	print(' '.join(map(str, a)))
else:
	for t in range(1, 1 << n):
		a.append(t ^ t - 1)
	print(len(a))
	print(' '.join(map(str, a)))


(n, x) = map(int, input().split())
if x >= 2 ** n:
	prefix_array = []
	for i in range(1, 2 ** n):
		prefix_array.append(i)
else:
	prefix_array = []
	compl = {}
	for i in range(1, 2 ** n):
		if i == x:
			continue
		try:
			if compl[i]:
				pass
		except:
			prefix_array.append(i)
			compl[i ^ x] = True
if prefix_array == []:
	print(0)
else:
	res = [prefix_array[0]]
	for i in range(len(prefix_array) - 1):
		res.append(prefix_array[i] ^ prefix_array[i + 1])
	print(len(res))
	for i in res:
		print(i, end=' ')
	print()


(n, x) = map(int, input().split())
vis = set([0])
res = []
cur = 0
for c in range(1, 1 << n):
	v = c ^ x
	if c in vis or v in vis:
		continue
	vis.add(c)
	res.append(c ^ cur)
	cur = c
print(len(res))
if res:
	print(' '.join(map(str, res)))


(n, x) = map(int, input().split())
d = []
for i in range(2 ** n):
	if i < i ^ x:
		d.append(i)
print(len(d) - 1)
for i in range(1, len(d)):
	print(d[i] ^ d[i - 1], end=' ')


(n, x) = map(int, input().split())
ans = []
total = 1 << n
vis = [0] * (1 << 18)
for i in range(total):
	if vis[i] == 0:
		ans.append(i)
		vis[i] = 1
		vis[i ^ x] = 1
print(len(ans) - 1)
for i in range(1, len(ans)):
	print(ans[i] ^ ans[i - 1], end=' ')


def main():
	buf = input()
	buflist = buf.split()
	n = int(buflist[0])
	x = int(buflist[1])
	npow2 = int(2 ** n)
	if n == 1:
		if x == 1:
			print(0)
		else:
			print(1)
			print(1)
		return
	mask = x
	if x >= npow2:
		mask = 0
	available = set()
	for i in range(1, npow2):
		if i != x:
			available.add(i)
	a = []
	while available:
		new_elem = available.pop()
		new_elem = new_elem ^ mask
		a.append(new_elem)
		if x < npow2:
			elem_to_remove = new_elem ^ x
			available.remove(elem_to_remove ^ mask)
		mask = mask ^ new_elem
	print(len(a))
	print(' '.join(list(map(str, a))))

def __starting_point():
	main()
__starting_point()


import io, os
(n, x) = map(int, input().split())
mark = [0 for x in range(1 << 18 + 1)]
mark[x] = 1
cur = 0
MAXN = 1 << n
ans = []
for i in range(1, MAXN):
	if i != x:
		res = i ^ x
		if mark[i] == 0:
			ans.append(i ^ cur)
			mark[res] = mark[i] = 1
			cur = i
print(len(ans))
print(*ans)


(n, x) = map(int, input().split())

def creat(n, x):
	if x > 2 ** n:
		arr = [i for i in range(1, 2 ** n)]
		return arr
	used = {i: False for i in range(1, 2 ** n)}
	arr = []
	for i in range(1, 2 ** n):
		if i == x:
			continue
		if used[i] == True:
			continue
		used[i] = True
		used[i ^ x] = True
		arr.append(i)
	return arr
a = creat(n, x)
if len(a) == 0:
	print(0)
else:
	a_ = [a[0]]
	a_.extend([u ^ v for (u, v) in zip(a[1:], a[:-1])])
	print(len(a_))
	print(' '.join([str(i) for i in a_]))


from sys import stdin

def input():
	return stdin.readline().strip()
import math
(n, x) = map(int, input().split())
seen = [False] * 2 ** 18
seen[0] = True
seen[x] = True
a = []
pref_sum = 0
for i in range(2 ** n):
	if seen[i]:
		continue
	a.append(pref_sum ^ i)
	pref_sum = i
	seen[i] = True
	seen[x ^ i] = True
print(len(a))
print(*a)


(n, x) = [int(x) for x in input().split(' ')]
b = []
if x >= 2 ** n:
	b = list(range(0, 2 ** n, 1))
else:
	forb = {}
	for i in range(2 ** n):
		if i not in forb:
			b.append(i)
			forb[i ^ x] = 1
a = [b[i] ^ b[i - 1] for i in range(1, len(b))]
print(len(a))
print(' '.join([str(x) for x in a]))


(N, X) = map(int, input().split())
ex = [False] * 2 ** 18
ex[0] = True
ans = [0]
for i in range(1, 2 ** N):
	if ex[i ^ X]:
		continue
	else:
		ans.append(i)
		ex[i] = True
print(len(ans) - 1)
for i in range(1, len(ans)):
	print(ans[i] ^ ans[i - 1], end=' ')


l = input().split()
n = int(l[0])
x = int(l[1])
hashi = dict()
for i in range(1, 2 ** n):
	hashi[i] = 1
pref = [0]
for i in range(1, 2 ** n):
	if i in hashi and i != x:
		pref.append(i)
		curr = x ^ i
		if curr in hashi:
			del hashi[curr]
if pref == [0]:
	print(0)
else:
	fina = []
	for i in range(1, len(pref)):
		fina.append(pref[i] ^ pref[i - 1])
	print(len(fina))
	for i in fina:
		print(i, end=' ')
	print()


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, x) = map(int, input().split())
	ans = [0]
	for i in range(1, pow(2, n)):
		if i ^ x > i:
			ans.append(i)
	print(len(ans) - 1)
	for i in range(1, len(ans)):
		print(ans[i] ^ ans[i - 1], end=' ')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

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

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

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	(n, x) = RL()
	up = 2 ** n
	rec = [0] * 2 ** 18
	res = []
	for i in range(up):
		if rec[i] == 0:
			rec[i] = 1
			rec[i ^ x] = 1
			res.append(i)
	print(len(res) - 1)
	for i in range(len(res) - 1):
		print(res[i] ^ res[i + 1], end=' ')
main()


(n, x) = map(int, input().split())
flag = [True] * (1 << n)
flag[0] = False
if x <= (1 << n) - 1:
	flag[x] = False
	for S in range(1 << n):
		if not flag[S]:
			continue
		flag[S ^ x] = False
xor = [0]
for S in range(1 << n):
	if flag[S]:
		xor.append(S)
ans = []
for i in range(len(xor) - 1):
	ans.append(xor[i] ^ xor[i + 1])
print(len(ans))
print(*ans)


def gns():
	return [int(x) for x in input().split()]
(n, x) = gns()
if n == 1:
	if x == 1:
		print(0)
		quit()
	print(1)
	print(1)
	quit()
b = len(bin(x)) - 2
if x != 1:
	ans = [1]
else:
	ans = [2]
cur = 1
for i in range(n - 2):
	if cur == b - 1:
		cur += 1
	ans = ans + [1 << cur] + ans
	cur += 1
if x >= 1 << n:
	ans = ans + [1 << cur] + ans
y = x
print(len(ans))
print(' '.join(map(str, ans)))


from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt

def geti():
	return map(int, input().strip().split())

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

def getis():
	return map(str, input().strip().split())

def getls():
	return list(map(str, input().strip().split()))

def gets():
	return input().strip()

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def create(n, a, b):
	ans = []
	for i in range(n):
		if i & 1:
			ans.append(b)
		else:
			ans.append(a)
	return ans

def solve():
	(n, x) = geti()
	xor = 0
	occur = {xor: True}
	ans = []
	ok = True
	while ok:
		ok = False
		for i in range(1, 1 << n):
			xor ^= i
			if xor in occur or xor ^ x in occur:
				xor ^= i
				continue
			else:
				occur[xor] = True
				ok = True
				ans.append(i)
	print(len(ans))
	if ans:
		print(*ans)
solve()


import sys
input = sys.stdin.readline
(n, x) = map(int, input().split())
b = [0]
for i in range(1, 2 ** n):
	if i ^ x > i:
		b.append(i)
a = [b[i] ^ b[i - 1] for i in range(1, len(b))]
print(len(a))
print(*a)


from functools import lru_cache

@lru_cache(maxsize=100000)
def rec(n):
	if n <= 0:
		return []
	if n == 1:
		return [1]
	l = rec(n - 1)
	return l + [2 ** (n - 1)] + l
(n, x) = map(int, input().split())
l = []
if x >= 2 ** n:
	l = rec(n)
else:
	l = rec(n - 1)
	b = len(bin(x))
	for (i, j) in enumerate(l):
		c = len(bin(j))
		if c >= b:
			l[i] *= 2
print(len(l))
if len(l) != 0:
	print(*l)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, OrderedDict
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
(n, x) = listIn()
a = {0, x}
ans = []
for i in range(1, 2 ** n):
	if i not in a and i ^ x not in a:
		ans.append(i)
		a.add(i)
if len(ans) > 0:
	res = [ans[0]]
	for i in range(1, len(ans)):
		res.append(ans[i] ^ ans[i - 1])
	print(len(res))
	print(*res)
else:
	print(0)


(n, x) = map(int, input().split())
res = []
s = {x}
prev = 0
for i in range(1, 1 << n):
	curr = prev ^ i
	if curr in s:
		continue
	res.append(curr)
	prev = i
	s.add(x ^ i)
print(len(res))
print(*res)


d = dict()

def solve(n):
	if n == 0:
		return []
	if n == 1:
		d[1] = [1]
		return d[1]
	if n in d:
		return d[n]
	else:
		d[n] = solve(n - 1) + [2 ** n - 1] + solve(n - 1)
		return d[n]

def solve2(n, x):
	if 2 ** (n - 1) <= x:
		return solve(n - 1)
	else:
		L = solve2(n - 1, x)
		return L + [2 ** (n - 1)] + L
solve(18)
(n, x) = map(int, input().split())
if x >= 2 ** n:
	L = solve(n)
	print(len(L))
	for i in L:
		print(i, end=' ')
else:
	L = solve2(n, x)
	print(len(L))
	for i in L:
		print(i, end=' ')


(n, x) = [int(i) for i in input().split()]
from collections import defaultdict as dd
done = dd(int)
ans = [0]
done[0] = 1
for i in range(1, 2 ** n):
	if done[i ^ x]:
		continue
	done[i] = 1
	ans.append(i)
gen = []
for i in range(1, len(ans)):
	gen.append(ans[i - 1] ^ ans[i])
print(len(gen))
print(*gen)


(n, x) = list(map(int, input().split()))
mark = [0 for x in range(1 << 18 + 1)]
mark[x] = 1
cur = 0
MAXN = 1 << n
ans = []
for i in range(1, MAXN):
	if i != x:
		res = i ^ x
		if mark[i] == 0:
			ans.append(i ^ cur)
			mark[res] = 1
			mark[i] = 1
			cur = i
print(len(ans))
print(*ans)


(n, x) = map(int, input().split())
ans = []
last = 0
for i in range(1, 2 ** n):
	if i ^ x > i:
		ans.append(last ^ i)
		last = i
print(len(ans))
for i in ans:
	print(i, end=' ')


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
(n, x) = map(int, input().split())
if x >= 2 ** n:
	b = [i for i in range(1, 2 ** n)]
else:
	b = list()
	s = set()
	for i in range(1, 2 ** n):
		if i == x or i in s:
			continue
		b.append(i)
		s.add(x ^ i)
if len(b) == 0:
	print(0)
else:
	print(len(b))
	a = [b[0]]
	for i in range(1, len(b)):
		a.append(b[i] ^ b[i - 1])
	print(*a)


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
(n, x) = map(int, input().split())
taken = {0, x}
b = [0]
for i in range(1, 1 << n):
	if i not in taken and i ^ x not in taken:
		b.append(i)
		taken.add(i)
b = [b[i] ^ b[i - 1] for i in range(1, len(b))]
print(len(b))
print(*b)


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	(n, x) = mi()
	m = {}
	pre = []
	for i in range(1, 1 << n):
		if i == x:
			continue
		if i ^ x not in m:
			pre.append(i)
		m[i] = 1
	if len(pre) == 0:
		print(0)
		return
	a = [0] * len(pre)
	a[0] = pre[0]
	for i in range(1, len(pre)):
		a[i] = pre[i] ^ pre[i - 1]
	print(len(a))
	print(*a)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


(n, x) = map(int, input().split())
mark = [0 for x in range(1 << 18 + 1)]
mark[x] = 1
curent = 0
maxA = 1 << n
ans = []
for i in range(1, maxA):
	if i != x:
		result = i ^ x
		if mark[i] == 0:
			ans.append(i ^ curent)
			mark[result] = 1
			mark[i] = 1
			curent = i
		elif mark[result] == 0 and result < maxA:
			ans.append(curent ^ result)
			mark[result] = 1
			curent = result
print(len(ans))
print(*ans)


(n, x) = list(map(int, input().split()))
n = 1 << n
ans = (n >> (x < n)) - 1
print(ans)
(q, t) = (0, 0)
a = [0] * n
for i in range(1, n):
	if i < i ^ x:
		a[t] = i ^ q
		(q, t) = (i, t + 1)
print(*a[:t])


from sys import stdout
(n, x) = list(map(int, input().split()))
t = pow(2, n)
if x >= t:
	print(t - 1)
	for i in range(1, t):
		stdout.write(str(i ^ i - 1) + ' ')
	exit(0)
ans = [0] * pow(2, n)
ans[x] = -1
for i in range(1, len(ans)):
	if ans[i] != -1:
		ans[x ^ i] = -1
last = 0
print(pow(2, n - 1) - 1)
for i in range(1, len(ans)):
	if ans[i] == 0:
		stdout.write(str(i ^ last) + ' ')
		last = i


(n, x) = [int(x) for x in input().split()]
ans = []
vis = [0] * (2 ** 18 + 1)
lmt = 2 ** n
xor = 0
(vis[0], vis[x]) = (1, 1)
for i in range(1, lmt):
	if vis[i]:
		continue
	ans.append(xor ^ i)
	xor = i
	vis[i] = 1
	vis[i ^ x] = 1
print(len(ans))
print(*ans)


(n, x) = map(int, input().split())
r = []
d = set()
for a in range(1, 2 ** n):
	tmp = x ^ a
	if tmp not in d and a not in d and (a not in (0, x)):
		r.append(a)
		d.add(a)
if not r:
	print(0)
else:
	res = [r[0]]
	for i in range(1, len(r)):
		res.append(r[i - 1] ^ r[i])
	print(len(res))
	print(' '.join(map(str, res)))


(n, x) = list(map(int, input().split()))
a = []
lst = 0
for i in range(1, 1 << n):
	if i ^ x > i:
		a.append(i ^ lst)
		lst = i
print(len(a))
print(' '.join((str(i) for i in a)))


def main():
	(n, x) = list(map(int, input().split()))
	f = []
	n = 1 << n
	cx = [0 for _ in range(n + 299)]
	for i in range(n):
		if Find_x(int(x ^ i), f) == False:
			f.append(i)
	print(len(f) - 1)
	for i in range(len(f) - 1):
		print(f[i] ^ f[i + 1], end=' ')

def Find_x(x, a):
	l = 0
	r = len(a) - 1
	while l <= r:
		m = int((l + r) / 2)
		if a[m] == x:
			return True
		if a[m] > x:
			r = m - 1
		else:
			l = m + 1
	return False

def __starting_point():
	main()
__starting_point()


from sys import stdin
input = stdin.readline
(n, x) = map(int, input().split())
x = 1 << len(bin(x)) - 3
a = [i for i in range(1, 1 << n) if i >> len(bin(x)) - 3 & 1 == 0] + [0]
b = [a[i] ^ a[i - 1] for i in range(len(a) - 1)]
print(len(b), *b)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from heapq import heappush as hpush
from heapq import heappop as hpop
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
(n, x) = ri()
ans = []
vis = [0 for i in range((1 << 18) + 1)]
start = 0
ans.append(start)
vis[0] = 1
for i in range(1, 1 << n):
	if vis[i ^ x] == 1:
		continue
	ans.append(i)
	vis[i] = 1
print(len(ans) - 1)
for i in range(1, len(ans)):
	print(ans[i] ^ ans[i - 1], end=' ')


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 30, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(1):
	(n, k) = map(int, input().split())
	done = set()
	l = []
	ans = []
	for i in range(1, 2 ** n):
		if i ^ k not in done and i ^ k != 0:
			l.append(i)
			done.add(i)
	print(len(l))
	if l != []:
		ans.append(l[0])
	for i in range(1, len(l)):
		ans.append(l[i] ^ l[i - 1])
	print(*ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		self.num_sets -= 1
		self.parent[a] = b
		self.size[b] += self.size[a]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def lcm(a, b):
	return abs(a // gcd(a, b) * b)

def solve():
	(n, x) = sep()
	s = set()
	s.add(x)
	ar = []
	for i in range(1, 1 << n):
		if i not in s:
			ar.append(i)
			s.add(i ^ x)
	if not ar:
		print(0)
		return
	ans = [ar[0]]
	for i in range(1, len(ar)):
		ans.append(ar[i] ^ ar[i - 1])
	print(len(ans))
	print(*ans)
solve()


(n, x) = list(map(int, input().split()))
(k, b) = (1 << n, [])
if x >= k:
	print(k - 1)
	b = list(range(1, k))
else:
	print(k - 2 >> 1)
	(_b, b) = (set(range(1, k)), set())
	for bi in _b:
		b.add(bi)
		if x ^ bi in b:
			b.remove(x ^ bi)
	if x in b:
		b.remove(x)
if b:
	b = list(b)
	a = [b[0]] + [b[i] ^ b[i + 1] for i in range(len(b) - 1)]
	print(*a)


from math import *
(n, x) = map(int, input().split())
ch = [0 for i in range(int(pow(2, 18) + 1))]
count = 0
for i in range(int(pow(2, n))):
	if ch[i] == 0:
		ch[i ^ x] = 1
		count += 1
prev = 0
print(count - 1)
for i in range(1, int(pow(2, n))):
	if ch[i] == 0:
		print(prev ^ i, end=' ')
		prev = i
print()