In some other world, today is Christmas.
Mr. Takaha decides to make a multi-dimensional burger in his party. A level-L burger (L is an integer greater than or equal to 0) is the following thing:
 - A level-0 burger is a patty.
 - A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom.
For example, a level-1 burger and a level-2 burger look like BPPPB and BBPPPBPBPPPBB (rotated 90 degrees), where B and P stands for a bun and a patty.
The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?

-----Constraints-----
 - 1 \leq N \leq 50
 - 1 \leq X \leq ( the total number of layers in a level-N burger )
 - N and X are integers.

-----Input-----
Input is given from Standard Input in the following format:
N X

-----Output-----
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger.

-----Sample Input-----
2 7

-----Sample Output-----
4

There are 4 patties in the bottom-most 7 layers of a level-2 burger (BBPPPBPBPPPBB).

Difficulty: MEDIUM_HARD

Solutions:
def dfs(n, x):
	if n == 0:
		return 0 if x <= 0 else 1
	elif x <= 1 + a[n - 1]:
		return dfs(n - 1, x - 1)
	else:
		return p[n - 1] + 1 + dfs(n - 1, x - 2 - a[n - 1])
(n, x) = map(int, input().split())
(a, p) = ([1], [1])
for i in range(n):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)
print(dfs(n, x))


(n, x) = list(map(int, input().split()))
(pate, slice) = ([1], [1])
for _ in range(n):
	pate.append(2 * pate[-1] + 1)
	slice.append(2 * slice[-1] + 3)
ans = 0
for i in range(n)[::-1]:
	if x >= slice[i] + 2:
		ans += pate[i] + 1
		x -= slice[i] + 2
	elif x < slice[i] + 2:
		x -= 1
print(ans + (x > 0))


(N, X) = map(int, input().split())
p = [0] * (N + 1)
num = [0] * (N + 1)
for i in range(N + 1):
	p[i] = 2 ** (i + 1) - 1
for i in range(N + 1):
	num[i] = 2 ** (i + 2) - 3

def f(L, x):
	if L == 0:
		return 0 if x <= 0 else 1
	elif x < (2 ** (L + 2) - 4) // 2 + 1:
		return f(L - 1, x - 1)
	else:
		return p[L - 1] + 1 + f(L - 1, x - 2 - num[L - 1])
print(f(N, X))


def resolve():
	(N, X) = map(int, input().split())
	As = [1]
	Ps = [1]
	for i in range(N):
		As.append(As[i] * 2 + 3)
		Ps.append(Ps[i] * 2 + 1)

	def f(n, x):
		if n == 0:
			return 0 if x <= 0 else 1
		mid = (As[n] + 1) // 2
		if x < mid:
			return f(n - 1, x - 1)
		elif x == mid:
			return Ps[n - 1] + 1
		elif x > mid:
			return Ps[n - 1] + 1 + f(n - 1, x - mid)
	ans = f(N, X)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


(n, x) = map(int, input().split())
(a, p) = ([1], [1])
for i in range(n):
	a += [a[i] * 2 + 3]
	p += [p[i] * 2 + 1]

def f(n, x):
	return int(x > 0) if n < 1 else p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1]) if x > a[n] // 2 else f(n - 1, x - 1)
print(f(n, x))


p = lambda n: 2 ** (n + 1) - 1
a = lambda n: 2 ** (n + 2) - 3

def f(n, x):
	if n == 0:
		return 0 if x <= 0 else 1
	if x > 1 + a(n - 1):
		return p(n - 1) + 1 + f(n - 1, x - 2 - a(n - 1))
	return f(n - 1, x - 1)
(n, x) = map(int, input().split())
print(f(n, x))


(N, X) = map(int, input().split())
a = [1]
p = [1]
for i in range(N):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def f(N, X):
	if N == 0:
		if X <= 0:
			return 0
		else:
			return 1
	elif X <= 1 + a[N - 1]:
		return f(N - 1, X - 1)
	else:
		return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1])
print(f(N, X))


(n, x) = list(map(int, input().split()))
(a, b) = ([1], [1])
for i in range(n):
	a.append(a[i] * 2 + 3)
	b.append(b[i] * 2 + 1)

def cal(n, x):
	if n == 0:
		if x <= 0:
			return 0
		else:
			return 1
	val = (a[n] + 1) // 2
	if x < val:
		return cal(n - 1, x - 1)
	elif x == val:
		return b[n - 1] + 1
	elif x > val:
		return b[n - 1] + 1 + cal(n - 1, x - val)
ans = cal(n, x)
print(ans)


(N, X) = map(int, input().split())
(l, p) = ([1], [1])
for i in range(N):
	l.append(l[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def patty(n, x):
	if n == 0:
		if x > 0:
			return 1
		else:
			return 0
	elif x <= 1 + l[n - 1]:
		return patty(n - 1, x - 1)
	else:
		return p[n - 1] + 1 + patty(n - 1, x - 2 - l[n - 1])
print(patty(N, X))


(L, X) = map(int, input().split())
b = [1]
p = [1]
for i in range(L):
	b.append(b[-1] * 2 + 3)
	p.append(p[-1] * 2 + 1)

def f(L, X):
	if L == 0 or X < 0:
		return 0 + (X > 0)
	elif X <= 1 + b[L - 1]:
		return f(L - 1, X - 1)
	else:
		return p[L - 1] + 1 + f(L - 1, X - b[L - 1] - 2)
print(f(L, X))


(N, X) = map(int, input().split())
siz = [1]
pat = [1]
for i in range(N):
	siz.append(siz[-1] * 2 + 3)
	pat.append(pat[-1] * 2 + 1)

def rec(n, x):
	if n == 0:
		ret = int(x > 0)
	elif x <= 1 + siz[n - 1]:
		ret = rec(n - 1, x - 1)
	else:
		ret = pat[n - 1] + 1 + rec(n - 1, x - 2 - siz[n - 1])
	return ret
print(rec(N, X))


(n, x) = map(int, input().split())
(l, p) = ([1], [1])
for i in range(n):
	l += [l[-1] * 2 + 3]
	p += [p[-1] * 2 + 1]
x -= 1
a = 1
while n:
	t = l[n] // 2
	if x >= t:
		a += p[n - 1] + 1
		x -= t
	x -= 1
	n -= 1
if x < 0:
	a -= 1
print(a)


def hamb(n, x):
	if x <= n:
		return 0
	elif x == 1 and n == 0:
		return 1
	elif x <= s[n - 1] + 1:
		return hamb(n - 1, x - 1)
	elif x == s[n]:
		return p[n]
	else:
		return hamb(n - 1, x - 2 - s[n - 1]) + p[n - 1] + 1
(n, x) = map(int, input().split())
s = [0] * (n + 1)
p = [0] * (n + 1)
s[0] = 1
p[0] = 1
for i in range(n):
	s[i + 1] = 3 + 2 * s[i]
	p[i + 1] = 1 + 2 * p[i]
print(hamb(n, x))


def main():
	import sys

	def input():
		return sys.stdin.readline().rstrip()

	def f(n, x):
		if n == 0:
			return 0 if x <= 0 else 1
		elif x <= a[n - 1] + 1:
			return f(n - 1, x - 1)
		else:
			return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1])
	(n, x) = map(int, input().split())
	(a, p) = ([1], [1])
	for i in range(n):
		a.append(2 * a[-1] + 3)
		p.append(2 * p[-1] + 1)
	print(f(n, x))

def __starting_point():
	main()
__starting_point()


(n, x) = map(int, input().split())
P = [1]
A = [1]
for i in range(n):
	P.append(P[i] * 2 + 1)
	A.append(A[i] * 2 + 3)

def f(n, x):
	if n == 0:
		return 0 if x <= 0 else 1
	elif x <= A[n - 1] + 1:
		return f(n - 1, x - 1)
	else:
		return P[n - 1] + 1 + f(n - 1, x - A[n - 1] - 2)
print(f(n, x))


(N, X) = list(map(int, input().split()))
size = [1]
patty = [1]
for i in range(N):
	size.append(size[i] * 2 + 3)
	patty.append(patty[i] * 2 + 1)

def f(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= size[N - 1] + 1:
		return f(N - 1, X - 1)
	elif X == size[N - 1] + 2:
		return patty[N - 1] + 1
	elif X >= size[N - 1] + 3:
		return patty[N - 1] + 1 + f(N - 1, X - size[N - 1] - 2)
print(f(N, X))


import sys
input = sys.stdin.readline
(N, X) = (int(i) for i in input().split())
DP_all = [0] * (N + 1)
DP_p = [0] * (N + 1)
DP_all[0] = 1
DP_p[0] = 1
for i in range(N):
	DP_all[i + 1] = DP_all[i] * 2 + 3
	DP_p[i + 1] = DP_p[i] * 2 + 1

def p_num(L, x):
	if x <= L:
		return 0
	if x == DP_all[L]:
		return DP_p[L]
	elif x < DP_all[L] // 2 + 1:
		return p_num(L - 1, x - 1)
	elif x == DP_all[L] // 2 + 1:
		return DP_p[L - 1] + 1
	elif x > DP_all[L] // 2 + 1:
		return DP_p[L - 1] + 1 + p_num(L - 1, x - DP_all[L - 1] - 2)
ans = p_num(N, X)
print(ans)


(N, X) = map(int, input().split())

def bisearch(n, l):
	if l <= 0:
		return 0
	half = (2 ** (n + 2) - 3) // 2
	if half < l:
		return 2 ** n + bisearch(n - 1, min(l - 1 - half, half))
	else:
		return bisearch(n - 1, l - 1)
print(bisearch(N, X))


def main():
	(N, X) = list(map(int, input().split()))
	p = [None] * (N + 1)
	p[0] = 1
	for i in range(N):
		p[i + 1] = 2 * p[i] + 1
	whole = [None] * (N + 1)
	whole[0] = 1
	for i in range(N):
		whole[i + 1] = 2 * whole[i] + 3

	def rec(N, X):
		if N == 0:
			if X == 1:
				return 1
			else:
				return 0
		if X <= 1:
			return 0
		elif X <= 1 + whole[N - 1]:
			return rec(N - 1, X - 1)
		elif X <= 1 + whole[N - 1] + 1:
			return p[N - 1] + 1
		elif X <= 1 + whole[N - 1] + 1 + whole[N - 1]:
			return p[N - 1] + 1 + rec(N - 1, X - (1 + whole[N - 1] + 1))
		else:
			return p[N - 1] + 1 + p[N - 1]
	ans = rec(N, X)
	return ans
print(main())


import sys
sys.setrecursionlimit(10 ** 6)
(N, X) = map(int, input().split())
(a, p) = ([1], [1])
for i in range(N):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def f(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + a[N - 1]:
		return f(N - 1, X - 1)
	else:
		return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1])
print(f(N, X))


def DFS(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + B[N - 1]:
		return DFS(N - 1, X - 1)
	else:
		return P[N - 1] + 1 + DFS(N - 1, X - 2 - B[N - 1])
(n, x) = map(int, input().split())
(B, P) = ([1], [1])
for i in range(n):
	P.append(P[i] * 2 + 1)
	B.append(B[i] * 2 + 3)
print(DFS(n, x))


(n, x) = map(int, input().split())
a = [(1, 1)]
for _ in range(n):
	a += [(a[-1][0] * 2 + 3, a[-1][1] * 2 + 1)]
if a[-1][0] in (x, x - 1):
	print(a[-1][1])
	exit()
s = 0
for k in range(3, len(a) * 2 + 1):
	(i, j) = a[-k // 2]
	x -= k % 2
	if i <= x:
		x -= i
		s += j
		if x >= 1:
			x -= 1
			s += 1
print(s)


(n, x) = map(int, input().split())
l = [0]
for i in range(n):
	l.append(2 ** (i + 1) - 1)
m = [0]
for i in range(n + 1):
	m.append(2 ** (i + 2) - 3)
c = 0
for i in range(n, -1, -1):
	t = 2 ** (i + 1) - 1
	if x < t:
		x -= 1
	elif x == t:
		c += l[i] + 1
		x = 0
	else:
		c += l[i] + 1
		if x == m[i + 1]:
			x -= 1
		x = x - t
print(c)


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

def doit(l, x):
	layers = 2 ** (l + 1) - 3
	if x >= layers * 2 + 3:
		return 2 ** (l + 1) - 1
	elif x >= layers + 2:
		return doit(l - 1, x - layers - 2) + 2 ** l
	elif x >= 1:
		return doit(l - 1, x - 1)
	else:
		return 0
print(doit(n, x))


import sys
sys.setrecursionlimit(10 ** 6)

def main():
	(n, x) = map(int, input().split())
	ans = 0
	for i in range(n, -1, -1):
		if x == 0:
			break
		m = 4 * 2 ** i - 3
		if x == m:
			ans += 2 ** (i + 1) - 1
			break
		if x >= (m + 1) / 2:
			ans += 2 ** i
			x -= int((m + 1) / 2)
		else:
			x -= 1
	print(ans)
	return
main()


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

def p(n, x):
	if x <= n:
		return 0
	if n == 0:
		return 1
	i = 0
	while 2 ** (2 + i) - 3 + n - i <= x:
		i += 1
	if 2 ** (i + 1) - 2 + n - i == x:
		return 2 ** i - 1
	else:
		return 2 ** i + p(i - 1, x - (2 ** (i + 1) + n - i - 2) - 1)
print(p(n, x))


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
(n, x) = list(map(int, input().split()))
(a, p) = ([1], [1])
for i in range(n):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def f(n, x):
	if n == 0:
		return 0 if x <= 0 else 1
	elif x <= 1 + a[n - 1]:
		return f(n - 1, x - 1)
	else:
		return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1])
print(f(n, x))


import sys
sys.setrecursionlimit(10000)
(N, X) = map(int, input().split())
ans = 0
for n in range(N, -1, -1):
	if X > (2 ** (n + 2) - 3) / 2:
		ans += 2 ** n
		X = X - (2 ** (n + 1) - 3) - 2
	else:
		X -= 1
print(ans)


(N, X) = map(int, input().split())
(T, P) = ([1], [1])
for i in range(N):
	T.append(T[i] * 2 + 3)
	P.append(P[i] * 2 + 1)

def f(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + T[N - 1]:
		return f(N - 1, X - 1)
	else:
		return P[N - 1] + 1 + f(N - 1, X - 2 - T[N - 1])
print(f(N, X))


(n, x) = map(int, input().split())
l = 2 ** (n + 2) - 3
ans = 0
k = n
while l >= 1:
	if x == (l + 1) // 2:
		ans += 2 ** k
		break
	if x == (l + 1) // 2 - 1:
		ans += 2 ** k - 1
		break
	if x > (l + 1) // 2:
		ans += 2 ** k
		x -= (l + 1) // 2 - 1
	k -= 1
	x -= 1
	l = (l - 1) // 2 - 1
print(ans)


def f(n, x):
	if x <= 0:
		return 0
	if x >= 2 ** (n + 2) - 3:
		return 2 ** (n + 1) - 1
	return f(n - 1, x - 1) + f(0, x - 2 ** (n + 1) + 2) + f(n - 1, x - 2 ** (n + 1) + 1)
(n, x) = map(int, input().split())
print(f(n, x))


(N, X) = (int(x) for x in input().split())
a = [1]
p = [1]
for i in range(N):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def func(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + a[N - 1]:
		return func(N - 1, X - 1)
	else:
		return p[N - 1] + 1 + func(N - 1, X - 2 - a[N - 1])
print(func(N, X))


(N, X) = map(int, input().split())
a = [1]
p = [1]
for _ in range(N):
	a += [2 * a[-1] + 3]
	p += [2 * p[-1] + 1]

def fx(N, X):
	if N == 0:
		if X <= 0:
			return 0
		else:
			return 1
	elif X <= a[N - 1] + 1:
		return fx(N - 1, X - 1)
	else:
		return p[N - 1] + 1 + fx(N - 1, X - 2 - a[N - 1])
print(fx(N, X))


(n, x) = map(int, input().split())
cnt = 0
while n > 0 and x > 0:
	if x >= 2 ** (n + 1) - 1:
		cnt += 2 ** n
		x -= 2 ** (n + 1) - 1
	else:
		x -= 1
	n -= 1
if x >= 1:
	cnt += 1
print(cnt)


(n, x) = map(int, input().split())
t = [1]
p = [1]
for i in range(1, n + 1):
	t.append(3 + 2 * t[i - 1])
	p.append(1 + 2 * p[i - 1])

def pathi(n, x):
	if n == 0:
		return 0 if x <= 0 else 1
	elif x <= t[n - 1] + 1:
		return pathi(n - 1, x - 1)
	else:
		return p[n - 1] + 1 + pathi(n - 1, x - t[n - 1] - 2)
print(pathi(n, x))


(n, x) = map(int, input().split())
B = [1]
P = [1]
for i in range(n):
	B.append(2 * B[i] + 3)
	P.append(2 * P[i] + 1)

def cnt(n, x):
	if n == 0 and x <= 0:
		return 0
	if n == 0 and x >= 1:
		return 1
	m = (B[n] + 1) // 2
	if x < m:
		return cnt(n - 1, x - 1)
	elif x == m:
		return P[n - 1] + 1
	elif x > m:
		return P[n - 1] + 1 + cnt(n - 1, x - m)
print(cnt(n, x))


(n, x) = map(int, input().split())
(pate, slice) = ([1], [1])
for _ in range(n + 1):
	pate.append(2 * pate[-1] + 1)
	slice.append(2 * slice[-1] + 3)
ans = 0
while n > 0 and x > 0:
	if x >= slice[n - 1] + 2:
		ans += pate[n - 1] + 1
		x -= slice[n - 1] + 2
	elif x < slice[n - 1] + 2:
		x -= 1
	n -= 1
print(ans + (x > 0))


def main():
	(n, x) = map(int, input().split())
	pb = [1]
	p = [1]
	for _ in range(n):
		pb.append(pb[-1] * 2 + 3)
		p.append(p[-1] * 2 + 1)
	ans = 0
	for _ in range(n):
		if x == 0:
			break
		if x >= pb[-2] + 2:
			x -= pb[-2] + 2
			ans += 1 + p[-2]
		else:
			x -= 1
		pb.pop(-1)
		p.pop(-1)
	if x >= 1:
		ans += 1
	print(ans)
main()


(N, X) = map(int, input().split())
(a, p) = ([1], [1])
for _ in range(N):
	a.append(a[-1] * 2 + 3)
	p.append(p[-1] * 2 + 1)

def f(n, x):
	if n == 0:
		return 0 if x <= 0 else 1
	if x <= a[n - 1] + 1:
		return f(n - 1, x - 1)
	else:
		return p[n - 1] + 1 + f(n - 1, x - a[n - 1] - 2)
print(f(N, X))


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

def num_patty(n, x):
	if 2 ** (n + 2) - 3 <= x:
		return 2 ** (n + 1) - 1
	elif 2 ** (n + 1) <= x and x <= 2 ** (n + 2) - 4:
		return num_patty(n - 1, x - 2 ** (n + 1) + 1) + (2 ** n - 1) + 1
	elif x == 2 ** (n + 1) - 1:
		return 2 ** n - 1 + 1
	elif 2 <= x and x <= 2 ** (n + 1):
		return num_patty(n - 1, x - 1)
	else:
		return 0
print(num_patty(n, x))


(n, x) = map(int, input().split())
(p, q) = ([1] + [0] * n, [1] + [0] * n)
for i in range(1, n + 1):
	p[i] = p[i - 1] * 2 + 1
	q[i] = q[i - 1] * 2 + 3

def rec(i, x):
	if i == 0:
		return 1 if x >= 1 else 0
	mid = q[i - 1] + 2
	if x < mid:
		return rec(i - 1, x - 1)
	else:
		return p[i - 1] + 1 + rec(i - 1, x - mid)
print(rec(n, x))


(N, K) = map(int, input().split())
a = [1]
p = [1]
for i in range(N):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def find(N, K):
	if N == 0:
		return 0 if K <= 0 else 1
	elif K <= a[N - 1] + 1:
		return find(N - 1, K - 1)
	else:
		return p[N - 1] + 1 + find(N - 1, K - 2 - a[N - 1])
print(find(N, K))


def f(n, x):
	if n == 0:
		return 0 if x <= 0 else 1
	elif x <= 1 + b[n - 1]:
		return f(n - 1, x - 1)
	else:
		return 1 + p[n - 1] + f(n - 1, x - 2 - b[n - 1])
(N, X) = map(int, input().split())
(b, p) = ([1 for _ in range(N + 1)], [1 for _ in range(N + 1)])
for i in range(1, N + 1):
	b[i] = b[i - 1] * 2 + 3
	p[i] = p[i - 1] * 2 + 1
print(f(N, X))


(N, X) = map(int, input().split())
ans = 0

def rec(x, n):
	global ans
	if n == 0:
		if x >= 1:
			ans += 1
	elif x > 2 ** (n + 1) - 2:
		ans += 2 ** n - 1 + 1
		rec(x - (2 ** (n + 1) - 1), n - 1)
	else:
		rec(x - 1, n - 1)
rec(X, N)
print(ans)


(n, x) = map(int, input().split())
ans = 0
while x > 0:
	if n == 0:
		ans += 1
		break
	elif x == 1:
		break
	elif x >= 2 ** (n + 1) - 1:
		ans += 2 ** n
		x -= 2 ** (n + 1) - 1
		n -= 1
	elif x == 2 ** (n + 1) - 2:
		ans += 2 ** n - 1
		print(ans)
		exit()
	else:
		n -= 1
		x -= 1
print(ans)


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

def main():
	(N, X) = list(map(int, readline().split()))

	@lru_cache(maxsize=None)
	def rec1(i):
		if i == 0:
			return 1
		else:
			return 2 * rec1(i - 1) + 1

	@lru_cache(maxsize=None)
	def rec2(i):
		if i == 0:
			return 1
		else:
			return 2 * rec2(i - 1) + 3

	def rec(i, x):
		if x <= 0:
			return 0
		if i == 0:
			return 1
		x -= 1
		ans = 0
		if x > rec2(i - 1):
			x -= rec2(i - 1)
			ans += rec1(i - 1)
		else:
			ans += rec(i - 1, x)
			return ans
		if x > 0:
			x -= 1
			ans += 1
		else:
			return ans
		if x > rec2(i - 1):
			x -= rec2(i - 1)
			ans += rec1(i - 1)
		else:
			ans += rec(i - 1, x)
		return ans
	print(rec(N, X))
	return

def __starting_point():
	main()
__starting_point()


(N, X) = map(int, input().split())
ans = 0
for i in range(N, -1, -1):
	if X < 2 ** (i + 1) - 1:
		X -= 1
	elif X > 2 ** (i + 1) - 1:
		X -= 2 ** (i + 1) - 1
		ans += 2 ** i
	else:
		ans += 2 ** i
		break
	if X == 0:
		break
print(ans)


(n, k) = map(int, input().split())
pk = [1]
pz = [1]
for i in range(n):
	pk.append(pk[-1] * 2 + 1)
	pz.append(pz[-1] * 2 + 3)
ans = 0
for i in range(n, -1, -1):
	z = pz.pop()
	ka = pk.pop()
	if k >= z // 2:
		ans += ka // 2
		k -= z // 2
		if k:
			ans += 1
	if k:
		k -= 1
print(ans)


(n, x) = map(int, input().split())
(b, p) = ([1], [1])
for i in range(n):
	b.append(b[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def pate(n, x):
	if n == 0:
		if x <= 0:
			return 0
		else:
			return 1
	elif x <= 1 + b[n - 1]:
		return pate(n - 1, x - 1)
	else:
		return p[n - 1] + 1 + pate(n - 1, x - 2 - b[n - 1])
print(pate(n, x))


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

def all_putty(m):
	return 2 ** (m + 1) - 1
count = 0
for l in range(n + 1)[::-1]:
	mark = 2 ** (1 + l) - 1
	if x >= mark:
		count += all_putty(l - 1) + 1
		x -= mark
	else:
		x -= 1
print(count)


def a(n):
	return 2 ** (n + 2) - 3

def b(n):
	return 2 ** (n + 1) - 1
(N, X) = [int(s) for s in input().split()]
count = 0
while X > 0:
	if X == a(N):
		count += b(N)
		X -= a(N)
	elif X < a(N):
		X -= 1
		N -= 1
	else:
		X -= a(N) + 1
		count += b(N) + 1
print(count)


import sys
input = sys.stdin.readline
(N, X) = map(int, input().split())
b = [2 ** (i + 2) - 3 for i in range(N)]
p = [2 ** (i + 1) - 1 for i in range(N)]

def f(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + b[N - 1]:
		return f(N - 1, X - 1)
	else:
		return p[N - 1] + 1 + f(N - 1, X - 2 - b[N - 1])
print(f(N, X))


import sys
sys.setrecursionlimit(100000000)
(N, K) = map(int, input().split())
store = [pow(2, i + 1) - 1 for i in range(51)]

def maisu(n):
	return pow(2, n + 2) - 3

def burger(n, k):
	if k == maisu(n):
		return store[n]
	elif k <= 1:
		return 0
	elif (maisu(n) - 3) // 2 + 1 >= k:
		return burger(n - 1, k - 1)
	else:
		return burger(n - 1, k - (2 + maisu(n - 1))) + burger(n - 1, maisu(n - 1)) + 1
ans = burger(N, K)
print(ans)


(N, X) = map(int, input().split())
Total = [1]
Patties = [1]
for i in range(1, N + 1):
	Total.append(Total[i - 1] * 2 + 3)
	Patties.append(Patties[i - 1] * 2 + 1)

def Burger(N, X):
	if N == 0:
		if X <= 0:
			return 0
		else:
			return 1
	elif X <= 1 + Total[N - 1]:
		return Burger(N - 1, X - 1)
	else:
		return Patties[N - 1] + 1 + Burger(N - 1, X - 2 - Total[N - 1])
print(Burger(N, X))


import math
from math import gcd, pi, sqrt
INF = float('inf')
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
import bisect
from collections import Counter, deque

def i_input():
	return int(input())

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

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]

def main():
	(N, X) = i_map()
	(a, p) = ([1], [1])
	for i in range(N):
		a.append(a[i] * 2 + 3)
		p.append(p[i] * 2 + 1)

	def f(N, X):
		if N == 0:
			return 0 if X <= 0 else 1
		elif X <= 1 + a[N - 1]:
			return f(N - 1, X - 1)
		else:
			return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1])
	print(f(N, X))

def __starting_point():
	main()
__starting_point()


(N, X) = map(int, input().split())
thk = [1]
p = [1]
for i in range(N - 1):
	thk.append(2 * thk[-1] + 3)
	p.append(2 * p[-1] + 1)

def burger(N, X):
	if N == 0:
		if X <= 0:
			return 0
		else:
			return 1
	elif X <= thk[N - 1] + 1:
		return burger(N - 1, X - 1)
	else:
		return p[N - 1] + 1 + burger(N - 1, X - thk[N - 1] - 2)
print(burger(N, X))


(N, X) = map(int, input().split())
(a, p) = ([1], [1])
for n in range(N):
	a.append(a[n] * 2 + 3)
	p.append(p[n] * 2 + 1)

def xmas(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + a[N - 1]:
		return xmas(N - 1, X - 1)
	else:
		return p[N - 1] + 1 + xmas(N - 1, X - (a[N - 1] + 2))
print(xmas(N, X))


(n, x) = list(map(int, input().split()))
sizes = [1]
for i in range(n):
	sizes.append(2 * sizes[i] + 3)
prev = {}

def solve(n, x):
	if (n, x) in prev:
		return prev[n, x]
	elif n == 0:
		return 1 if x == 1 else 0
	else:
		ans = 0
		if x == sizes[n]:
			ans = 2 * solve(n - 1, sizes[n - 1]) + 1
		else:
			mid = sizes[n] // 2 + 1
			if x == mid:
				ans = solve(n - 1, sizes[n - 1]) + 1
			elif x < mid:
				ans = solve(n - 1, x - 1)
			else:
				ans = solve(n - 1, sizes[n - 1]) + 1 + solve(n - 1, x - mid)
		prev[n, x] = ans
		return ans
print(solve(n, x))


import copy
import random
import bisect
import fractions
import math
import sys
import collections
from decimal import Decimal
mod = 10 ** 9 + 7
sys.setrecursionlimit(mod)
d = collections.deque()

def LI():
	return list(map(int, sys.stdin.readline().split()))
(N, X) = LI()
(a, p) = ([1], [1])
for i in range(N):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def f(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + a[N - 1]:
		return f(N - 1, X - 1)
	else:
		return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1])
print(f(N, X))


def ans(n, x):
	if n < 0:
		return 0
	if x < 1:
		return 0
	if x < 2 ** (n + 1) - 1:
		return ans(n - 1, x - 1)
	if x == 2 ** (n + 1) - 1:
		return 2 ** n
	return 2 ** n + ans(n - 1, x - 2 ** (n + 1) + 1)
(N, X) = map(int, input().split())
print(ans(N, X))


(N, X) = map(int, input().split())
(num, p) = ([1], [1])
index = 1
while N >= index:
	num.append(2 * num[-1] + 3)
	p.append(2 * p[-1] + 1)
	index += 1

def ans(n, x):
	if n == 0:
		return 1 if x > 0 else 0
	if x <= num[n - 1] + 1:
		return ans(n - 1, x - 1)
	else:
		return p[n - 1] + 1 + ans(n - 1, x - 2 - num[n - 1])
print(ans(N, X))


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

def main():
	(N, X) = list(map(int, readline().split()))
	A = [0] * (N + 1)
	B = [0] * (N + 1)
	A[0] = B[0] = 1
	for i in range(N):
		A[i + 1] = 2 * A[i] + 3
		B[i + 1] = 2 * B[i] + 1

	def rec(i, x):
		if i == 0:
			return 1 if x > 0 else 0
		elif x <= 1 + A[i - 1]:
			return rec(i - 1, x - 1)
		else:
			return B[i - 1] + 1 + rec(i - 1, x - 2 - A[i - 1])
	print(rec(N, X))
	return

def __starting_point():
	main()
__starting_point()


(n, x) = map(int, input().split())
ans = 0
i = n
while i >= 0:
	c = 2 ** (i + 1) - 3
	num_p = 2 ** i - 1
	if 2 * c + 3 == x:
		ans += 2 * num_p + 1
		break
	elif c + 2 == x:
		ans += num_p + 1
		break
	elif 1 == x:
		break
	elif 2 + c <= x:
		x -= 2 + c
		ans += num_p + 1
	else:
		x -= 1
	i -= 1
print(ans)


(n, x) = list(map(int, input().split()))
a = [1] * (n + 1)
p = [1] * (n + 1)
for i in range(1, n + 1):
	a[i] = a[i - 1] * 2 + 3
	p[i] = p[i - 1] * 2 + 1

def count(l, x):
	if l == 0:
		if x >= 1:
			return 1
		else:
			return 0
	elif x == 1:
		return 0
	elif x < a[l - 1] + 2:
		return count(l - 1, x - 1)
	elif x == a[l - 1] + 2:
		return p[l - 1] + 1
	elif a[l] > x:
		return count(l - 1, x - a[l - 1] - 2) + p[l - 1] + 1
	else:
		return p[l]
print(count(n, x))


(N, X) = map(int, input().split())

def get_size(level):
	return (1 << level + 2) - 3

def get_patty(level):
	return (1 << level + 1) - 1
ans = 0
while X > 0:
	if get_size(N) > X:
		X -= 1
		N -= 1
	else:
		X -= get_size(N)
		ans += get_patty(N)
		if X > 0:
			ans += 1
			X -= 1
print(ans)


import sys
import math
(n, x) = map(int, input().split())
cntr = [1]
keta = [1]
for i in range(n):
	cntr.append(cntr[-1] * 2 + 1)
	keta.append(keta[-1] * 2 + 3)
ans = 0
for i in range(n, -1, -1):
	if x >= cntr[i]:
		ans += 2 ** i
		x -= cntr[i]
	else:
		x -= 1
print(ans)


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

def get_len(lv):
	m = 1
	for i in range(lv):
		m = m * 2 + 3
	return m

def count_p(lv, p):
	if p <= lv:
		return 0
	elif lv == 0:
		return 1
	m = get_len(lv)
	if p > (m - 1) / 2:
		return (m - 1) / 2 + 1 - count_p(lv, m - p)
	else:
		return count_p(lv - 1, p - 1)
print(int(count_p(n, x)))


import sys
sys.setrecursionlimit(10 ** 7)
(n, x) = map(int, input().split())
l = [0] * (n + 1)
c = [0] * (n + 1)
c[0] = l[0] = 1
for i in range(1, n + 1):
	l[i] = l[i - 1] * 2 + 3
	c[i] = c[i - 1] * 2 + 1

def check(r, t):
	if r == 0 and t > 0:
		return 1
	elif r == 0:
		return 0
	elif t <= l[r - 1] + 1:
		return check(r - 1, t - 1)
	else:
		return check(r - 1, t - l[r - 1] - 2) + c[r - 1] + 1
print(check(n, x))


import sys
sys.setrecursionlimit(10 ** 7)
(n, x) = map(int, input().split())
a = [0] * (n + 1)
p = [0] * (n + 1)
a[0] = 1
p[0] = 1
for i in range(n):
	a[i + 1] = 2 * a[i] + 3
	p[i + 1] = 2 * p[i] + 1

def func(i, x):
	if i == 0:
		if x <= 0:
			return 0
		elif x >= 1:
			return 1
	mid = (a[i] + 1) // 2
	if mid == x:
		return p[i - 1] + 1
	elif mid > x:
		return func(i - 1, x - 1)
	else:
		return p[i - 1] + 1 + func(i - 1, x - mid)
print(func(n, x))


(N, X) = (int(i) for i in input().split())
L = [1]
P = [1]
for _ in range(N):
	L.append(L[-1] * 2 + 3)
	P.append(P[-1] * 2 + 1)

def count(x, n):
	if n == 0:
		return 0 if x <= 0 else 1
	elif x <= L[n - 1] + 1:
		return count(x - 1, n - 1)
	else:
		return P[n - 1] + 1 + count(x - (L[n - 1] + 2), n - 1)
print(count(X, N))


def f(N, X):
	m = 2 ** (N + 1) - 1
	if X <= N:
		return 0
	elif N == 0:
		return 1
	elif X < m:
		return f(N - 1, X - 1)
	else:
		return 2 ** N + f(N - 1, X - m)
(N, X) = map(int, input().split())
print(f(N, X))


(N, X) = map(int, input().split())
t = [0] * (N + 1)
h = [0] * (N + 1)
h[0] = 1
t[0] = 1
for i in range(1, N + 1):
	h[i] = 2 * h[i - 1] + 3
	t[i] = 2 * t[i - 1] + 1

def find(n, x):
	if n == 0:
		return 0 if x <= 0 else 1
	elif x <= 1 + h[n - 1]:
		return find(n - 1, x - 1)
	else:
		return t[n - 1] + 1 + find(n - 1, x - 2 - h[n - 1])
print(find(N, X))