AtCoder Beginner Contest 115 - Christmas

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

Starter code:

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) = list(map(int, input().split()))

def solve(N, X):
	if X == 0:
		return 0
	if N == 0:
		return X
	if X < 2 ** (N + 1) - 1:
		return solve(N - 1, X - 1)
	elif X == 2 ** (N + 1) - 1:
		return 2 ** N
	elif X < 2 ** (N + 2) - 3:
		return 2 ** N + solve(N - 1, X - 2 ** (N + 1) + 1)
	else:
		return 2 ** (N + 1) - 1
print(solve(N, X))


(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 cnt(n, x):
	if x == 0:
		return 0
	elif n == 0:
		return 1
	elif x < 2 ** (n + 1) - 1:
		return cnt(n - 1, x - 1)
	elif x == 2 ** (n + 1) - 1:
		return 2 ** n
	elif x < 2 ** (n + 2) - 3:
		return cnt(n - 1, 2 ** (n + 1) - 3) + 1 + cnt(n - 1, x - 2 ** (n + 1) + 1)
	else:
		return 2 ** (n + 1) - 1
(n, x) = map(int, input().split())
print(cnt(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] * (N + 1)
P = [1] * (N + 1)
for i in range(1, N + 1):
	P[i] = 2 * P[i - 1] + 1
	A[i] = 2 * P[i] - 1

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


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

def eat(n, x):
	if x <= 1:
		return 0
	if x == l[n - 1] + 1:
		return bg[n - 1]
	if x == l[n] or x == l[n] - 1:
		return bg[n]
	if x <= l[n - 1]:
		return eat(n - 1, x - 1)
	return bg[n - 1] + 1 + eat(n - 1, x - l[n - 1] - 2)
print(eat(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))


def calc(n, k):
	if n == 0:
		return 1
	if k == 1:
		return 0
	len = 2 ** (n + 1) - 3
	if k <= len + 1:
		return calc(n - 1, k - 1)
	if k == len + 2:
		return calc(n - 1, len) + 1
	if k <= len + len + 2:
		return calc(n - 1, len) + 1 + calc(n - 1, k - len - 2)
	if k == len + len + 3:
		return 2 ** (n + 1) - 1
(n, k) = map(int, input().split())
print(calc(n, k))


(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) = list(map(int, input().split()))
p = [1] * -~n
l = [1] * -~n
for i in range(1, n + 1):
	p[i] = p[i - 1] * 2 + 1
	l[i] = l[i - 1] * 2 + 3

def rec(m, y):
	if y == 0:
		return 0
	if m == 0:
		return 1
	h = l[m] // 2
	if h < y:
		return 1 + p[m - 1] + rec(m - 1, y - h - 1)
	else:
		return rec(m - 1, y - 1)
print(rec(n, x))


(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))


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

def func(n, k):
	if n == 0:
		return 1
	a = 2 ** (n + 1) - 1
	if k == a:
		return 2 ** n
	elif k == 1:
		return 0
	elif k == 2 ** (n + 2) - 3:
		return 2 ** (n + 1) - 1
	elif k < a:
		return func(n - 1, k - 1)
	else:
		return 2 ** n + func(n - 1, k - (2 ** (n + 1) - 1))
print(func(N, X))


(n, x) = map(int, input().split())
l = [1]
for i in range(50):
	l += [l[-1] * 2 + 3]
from functools import lru_cache

@lru_cache(None)
def f(n, x):
	return int(x > 0) if n < 1 else f(n - 1, l[n - 1]) + 1 + f(n - 1, x - l[n - 1] - 2) if x > l[n] // 2 else f(n - 1, x - 1)
print(f(n, x))


(A, P) = ([1], [1])
for i in range(50):
	A.append(A[i] * 2 + 3)
	P.append(P[i] * 2 + 1)

def n(N, X):
	if X <= 0:
		return 0
	if N == 0:
		return 1
	return n(N - 1, X - 1) if X <= A[N - 1] + 1 else P[N - 1] + 1 + n(N - 1, X - (A[N - 1] + 2))
print(n(*list(map(int, input().split()))))


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

def b(n, x):
	if n == 0 and x == 1:
		return 1
	while n > 0:
		z = (2 ** (n + 2) - 3) // 2 + 1
		if x == 1:
			return 0
		elif 1 < x < z:
			return b(n - 1, x - 1)
		elif x == z:
			return 2 ** n
		elif z < x < 2 ** (n + 2) - 3:
			return 2 ** n + b(n - 1, x - z)
		else:
			return 2 ** (n + 1) - 1
print(b(n, x))


import sys
sys.setrecursionlimit(10 ** 5)
(N, X) = map(int, input().split())
layers = [1]
patties = [1]
for i in range(1, N + 1):
	layer_i = 2 * layers[i - 1] + 3
	patty_i = 2 * patties[i - 1] + 1
	layers.append(layer_i)
	patties.append(patty_i)

def f(n, x):
	if x == 1:
		return 1 if n == 0 else 0
	elif 1 < x <= 1 + layers[n - 1]:
		return f(n - 1, x - 1)
	elif x == 2 + layers[n - 1]:
		return patties[n - 1] + 1
	elif 2 + layers[n - 1] < x <= 2 + 2 * layers[n - 1]:
		return patties[n - 1] + 1 + f(n - 1, x - 2 - layers[n - 1])
	else:
		return 2 * patties[n - 1] + 1
print(f(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))


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


(N, X) = map(int, input().split())
L = [[1, 1] for _ in range(N + 1)]
i = 0
while i + 1 <= N:
	L[i + 1][0] = L[i][0] * 2 + 1
	L[i + 1][1] = L[i + 1][0] * 2 - 1
	i += 1
xx = [[1, 1, 1, 1, 1] for _ in range(N + 1)]
i = 0
while i + 1 <= N:
	xx[i + 1][1] = L[i][1] + 1
	xx[i + 1][2] = L[i][1] + 2
	xx[i + 1][3] = 2 * L[i][1] + 2
	xx[i + 1][4] = 2 * L[i][1] + 3
	i += 1
ans = 0
while N > 0:
	if xx[N][0] == X:
		break
	elif xx[N][1] >= X:
		N -= 1
		X -= 1
	elif xx[N][2] == X:
		ans += 1 + L[N - 1][0]
		break
	elif xx[N][3] >= X:
		ans += 1 + L[N - 1][0]
		X -= xx[N][2]
		N -= 1
	else:
		ans += 1 + 2 * L[N - 1][0]
		break
	if N == 0:
		ans += 1
print(ans)


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

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


(n, x) = list(map(int, input().split()))
b = 1
p = 1
for i in range(n):
	b = 2 * b + 3
	p = 2 * p + 1
x -= 1
b -= 1
ans = 0
while True:
	if x == 0:
		if b == 0:
			ans += 1
		break
	elif x == b:
		ans += p
		break
	elif x == b // 2:
		ans += p // 2 + 1
		break
	elif 0 < x < b // 2:
		x -= 1
	else:
		x -= b // 2 + 1
		ans += p // 2 + 1
	b = (b - 3) // 2
	p = (p - 1) // 2
print(ans)


(N, X) = map(int, input().split())
ans = 0
while X != 1 and X != 2 ** (N + 1) - 1 and (X != 2 ** (N + 2) - 3):
	if 1 < X < 2 ** (N + 1) - 1:
		X -= 1
		N -= 1
	else:
		ans += 2 ** N
		X -= 2 ** (N + 1) - 1
		N -= 1
if X == 2 ** (N + 1) - 1:
	ans += 2 ** N
elif X == 1:
	ans += 0
else:
	ans += 2 ** (N + 1) - 1
print(ans)


ip = input().split(' ')
n = int(ip[0])
x = int(ip[1])

def get_num_layers(level):
	if level == 1:
		return 5
	return 5 * (1 << level - 1) + 3 * ((1 << level - 1) - 1)

def func(level, index):
	if level == 1:
		return min(index - 1, 3)
	num_layers = get_num_layers(level)
	mid = num_layers // 2
	if index == mid + 1:
		return 1 + func(level - 1, mid - 1)
	if index == 1:
		return 0
	if index == num_layers:
		return 2 * func(level - 1, mid - 1) + 1
	if index <= mid:
		return func(level - 1, index - 1)
	if index > mid + 1:
		return 1 + func(level - 1, mid - 1) + func(level - 1, index - mid - 1)
print(func(n, x))


import sys
sys.setrecursionlimit(10 ** 9)

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

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

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

def deb(text):
	print('-------\n{}\n-------'.format(text))
INF = 10 ** 20

def main():
	(N, X) = mi()

	def solve(n, x):
		if n == 0:
			return 1
		c = 2 ** (n + 2) - 3
		half = c // 2
		res = 0
		if x <= half:
			if x == 1:
				res += 0
			else:
				res += solve(n - 1, x - 1)
		elif x == half + 1:
			res += 2 ** (n - 1 + 1) - 1 + 1
		elif x < c:
			res += 2 ** (n - 1 + 1) - 1 + 1 + solve(n - 1, x - (half + 1))
		else:
			assert x == c
			res += 2 ** (n + 1) - 1
		return res
	print(solve(N, X))

def __starting_point():
	main()
__starting_point()


import sys
sys.setrecursionlimit(10 ** 6)

def rec(level, x):
	l_len = pow(2, level + 2) - 3
	l_len_1 = pow(2, level + 1) - 3
	num = pow(2, level + 1) - 1
	num_1 = pow(2, level) - 1
	if level == 0:
		return 1
	if x == 0:
		return 0
	if x == 1:
		return 0
	if x <= l_len_1 + 1:
		return rec(level - 1, x - 1)
	if x <= l_len_1 + 2:
		return num_1 + 1
	if x <= l_len - 1:
		return num_1 + 1 + rec(level - 1, x - l_len_1 - 2)
	else:
		return num

def main():
	(n, x) = map(int, input().split())
	print(rec(n, x))

def __starting_point():
	main()
__starting_point()


(n, k) = 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, k):
	if n == 0:
		if k == 0:
			return 0
		else:
			return 1
	if k == 0:
		return 0
	elif k <= a[n - 1] + 1:
		return f(n - 1, k - 1)
	else:
		return p[n - 1] + 1 + f(n - 1, k - 2 - a[n - 1])
print(f(n, k))


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

def pbx(xx, nn):
	if nn == 0:
		return 1
	if xx == 1:
		return 0
	elif xx <= 1 + pb[nn - 1][0]:
		return pbx(xx - 1, nn - 1)
	elif xx == 2 + pb[nn - 1][0]:
		return pb[nn - 1][1] + 1
	elif xx <= 2 + pb[nn - 1][0] * 2:
		xxx = pbx(xx - pb[nn - 1][0] - 2, nn - 1)
		xxx = pb[nn - 1][1] + 1 + xxx
		return xxx
	elif xx == 3 + pb[nn - 1][0] * 2:
		return pb[nn][1]
	else:
		print(('----------', xx, nn))
		return 0
print(pbx(x, n))


a = [1]
b = [1]
for _ in range(50):
	a.append(2 * a[-1] + 3)
	b.append(2 * b[-1] + 1)

def num_of_patties(n, x):
	if n == 0:
		return 1
	if x == 1:
		return 0
	elif x <= a[n - 1] + 1:
		return num_of_patties(n - 1, x - 1)
	elif x == a[n - 1] + 2:
		return b[n - 1] + 1
	elif x <= 2 * a[n - 1] + 2:
		return b[n - 1] + 1 + num_of_patties(n - 1, x - a[n - 1] - 2)
	else:
		return b[n]
print(num_of_patties(*[int(i) for i in input().split()]))


(n, x) = map(int, input().split())
piece = [1]
meet = [1]
for _ in range(n):
	piece.append(piece[-1] * 2 + 3)
	meet.append(meet[-1] * 2 + 1)
ans = 0
i = n
while x:
	if x > (piece[i] + 1) // 2:
		ans += meet[i] // 2 + 1
		x -= piece[i] // 2 + 1
		i -= 1
	elif x == (piece[i] + 1) // 2:
		ans += meet[i] // 2 + 1
		x = 0
	else:
		i -= 1
		x -= 1
print(ans)


(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)


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

def rec(n, x):
	if x == 0:
		return 0
	if n == 0:
		return 1
	if x * 2 > h[n]:
		return 2 ** n + rec(n - 1, x - 1 - h[n] // 2)
	return rec(n - 1, x - 1)
print(rec(n, x))


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

def solve(n, i):
	if n == 0:
		return 1
	if i == 0:
		return 0
	if i < (2 ** (n + 2) - 3) // 2:
		return solve(n - 1, i - 1)
	if i == (2 ** (n + 2) - 3) // 2:
		return 2 ** n
	if i < 2 ** (n + 2) - 4:
		return 2 ** n + solve(n - 1, i - (2 ** (n + 2) - 3) // 2 - 1)
	return 2 ** (n + 1) - 1
print(solve(n, x - 1))


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

def rec(n, x):
	f = 2 ** (n + 1) - 3
	if n == 0:
		return 1
	if x == 1:
		return 0
	elif x <= f + 1:
		return rec(n - 1, x - 1)
	elif x == f + 2:
		return 2 ** n
	elif x <= 2 * f + 2:
		return 2 ** n + rec(n - 1, x - (2 ** (n + 1) - 1))
	else:
		return 2 ** (n + 1) - 1
print(rec(N, X))


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))


def levelup(X, N):
	if N == 0 and X != 0:
		return 1
	if X == 0:
		return 0
	elif X < 2 ** (N + 1) - 1:
		return levelup(X - 1, N - 1)
	elif X < 2 ** (N + 2) - 3:
		return 2 ** N - 1 + levelup(X - 2 ** (N + 1) + 1, N - 1) + 1
	elif X == 2 ** (N + 2) - 3:
		return 2 ** (N + 1) - 1
(N, X) = list(map(int, input().split()))
print(levelup(X, N))


import sys
stdin = sys.stdin
from functools import lru_cache

def ns():
	return stdin.readline().rstrip()

def ni():
	return int(ns())

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

@lru_cache(maxsize=2 ** 52 - 3)
def f(n, x):
	if n == 0:
		return 1
	if x == 1:
		return 0
	elif x <= 2 ** (n + 1) - 2:
		return f(n - 1, x - 1)
	elif x == 2 ** (n + 1) - 1:
		return f(n - 1, 2 ** (n + 1) - 3) + 1
	elif x < 2 ** (n + 2) - 2:
		return f(n - 1, 2 ** (n + 1) - 3) + 1 + f(n - 1, x - (2 ** (n + 1) - 1))
	else:
		return 2 * f(n - 1, 2 ** (n + 1) - 3) + 1

def main():
	(n, x) = na()
	print(f(n, x))

def __starting_point():
	main()
__starting_point()


(N, X) = list(map(int, input().split(' ')))
p = [1]
pb = [1]
np = 0
nx = X
for _ in range(N):
	p.append(p[-1] * 2 + 1)
	pb.append(pb[-1] * 2 + 3)

def dfs(level):
	nonlocal np, nx
	if nx == 0:
		return
	if nx >= pb[level]:
		nx -= pb[level]
		np += p[level]
		return
	nx -= 1
	if nx == 0:
		return
	dfs(level - 1)
	if nx == 0:
		return
	nx -= 1
	np += 1
	if nx == 0:
		return
	dfs(level - 1)
	if nx == 0:
		return
	nx -= 1
dfs(N)
print(np)


(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))


(n, x) = map(int, input().split())
patty = [1]
barger = [1]
ans = 0
for i in range(n):
	patty.append(2 * patty[-1] + 1)
	barger.append(2 * barger[-1] + 3)
i = n
while x > 0:
	for _ in range(n):
		if x >= barger[i]:
			x -= barger[i]
			ans += patty[i]
			if x > 0:
				ans += 1
				x -= 1
			break
		i -= 1
		x -= 1
print(ans)


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)


def solve():
	(n, x) = list(map(int, input().split()))
	l = [1]
	nu = [1]
	for i in range(n):
		l.append(l[-1] * 2 + 3)
		nu.append(nu[-1] * 2 + 1)

	def chris(a, b):
		if a == 0:
			return b
		elif b <= a:
			return 0
		hl = l[a]
		if b >= hl - a:
			return nu[a]
		elif hl // 2 + 1 <= b:
			return nu[a - 1] + 1 + chris(a - 1, b - (hl // 2 + 1))
		return chris(a - 1, b - 1)
	print(chris(n, x))
solve()


(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())


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

def dp(n, x):
	if x == 0:
		return 0
	if n == 0:
		return 1
	if x <= 2 ** (n + 1) - 2:
		return dp(n - 1, x - 1)
	else:
		return 2 ** n + dp(n - 1, x - 2 ** (n + 1) + 1)
print(dp(N, X))


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())
p = [1]
h = [1]
for i in range(50):
	p.append(1 + p[-1] * 2)
	h.append(3 + h[-1] * 2)

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


def f(L, x):
	if L == 0:
		return 0 if x <= 0 else 1
	if x <= total[L - 1] + 1:
		return f(L - 1, x - 1)
	else:
		return patties[L - 1] + 1 + f(L - 1, x - total[L - 1] - 2)
(N, X) = list(map(int, input().split()))
total = [1]
patties = [1]
for i in range(50):
	total.append(total[-1] * 2 + 3)
	patties.append(patties[-1] * 2 + 1)
print(f(N, X))


(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))


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

def main(n, x, ans):
	nonlocal X
	nonlocal l
	if n == 0:
		return ans + 1
	elif x == 1:
		return ans
	elif x == 2 * l[n] - 1:
		return ans + 2 * l[n - 1] + 1
	elif x == l[n]:
		return main(n - 1, x - 2, ans + 1)
	elif x < l[n]:
		return main(n - 1, x - 1, ans)
	else:
		return main(n - 1, x - 2 * l[n - 1] - 1, ans + l[n - 1] + 1)
a = main(N, X, 0)
print(a)


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()


from math import ceil, floor, factorial, gcd, sqrt, log2, cos, sin, tan, acos, asin, atan, degrees, radians, pi, inf, comb
from itertools import accumulate, groupby, permutations, combinations, product, combinations_with_replacement
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)

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

def INT():
	return int(input())

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

def LIST():
	return list(MAP())

def dfs(k):
	nonlocal count, ans
	count += 1
	if k == 0:
		ans += 1
	elif count < x:
		if count + b[k - 1] > x:
			dfs(k - 1)
		else:
			count += b[k - 1]
			ans += p[k - 1]
		if count < x:
			count += 1
			ans += 1
			if count < x:
				if count + b[k - 1] > x:
					dfs(k - 1)
				else:
					count += b[k - 1]
					ans += p[k - 1]
(n, x) = MAP()
b = [0] * n
p = [0] * n
b[0] = 1
p[0] = 1
for i in range(1, n):
	b[i] = b[i - 1] * 2 + 3
	p[i] = p[i - 1] * 2 + 1
count = 0
ans = 0
dfs(n)
print(ans)


(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))


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

def f(n, x):
	if x == 1:
		return 1 if n == 0 else 0
	if 1 < x and x <= 1 + lsa[n - 1]:
		return f(n - 1, x - 1)
	if x == 2 + lsa[n - 1]:
		return lsp[n - 1] + 1
	if 2 + lsa[n - 1] < x and x <= 2 + 2 * lsa[n - 1]:
		return lsp[n - 1] + 1 + f(n - 1, x - 2 - lsa[n - 1])
	if x == 3 + 2 * lsa[n - 1]:
		return 2 * lsp[n - 1] + 1
print(f(N, X))


(n, x) = list(map(int, input().split()))
dp = [1] * (n + 1)
res = 0
for i in range(1, n + 1):
	dp[i] = dp[i - 1] * 2 + 3
for j in range(n, 1, -1):
	if dp[j] == x:
		res += (dp[j] + 1) // 2
		x = 0
	elif dp[j - 1] + 2 <= x:
		res += 1 + (dp[j - 1] + 1) // 2
		x -= dp[j - 1] + 2
	elif dp[j - 1] + 1 == x:
		res += (dp[j - 1] + 1) // 2
		x = 0
	else:
		x -= 1
	if x == 0:
		break
if x == 5:
	res += 3
elif x == 0:
	pass
else:
	res += x - 1
print(res)


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))


def delete_head_zeros(n):
	n = str(n)
	l = len(n)
	if '.' in n:
		l = n.find('.')
	head_zeros = 0
	for i in range(l - 1):
		if n[i] == '0':
			head_zeros += 1
		else:
			break
	return n[head_zeros:]

def bigint_compare(a, b):
	a = delete_head_zeros(a)
	b = delete_head_zeros(b)
	if len(a) > len(b):
		return 1
	elif len(a) < len(b):
		return -1
	elif a > b:
		return 1
	elif a < b:
		return -1
	else:
		return 0

def bigint_plus(a, b):
	a = str(a)
	b = str(b)
	d = max([len(a), len(b)])
	a = '0' * (d - len(a)) + a
	b = '0' * (d - len(b)) + b
	ans = ''
	carry = 0
	for i in range(d):
		s = int(a[-i - 1]) + int(b[-i - 1]) + carry
		carry = s // 10
		ans = str(s % 10) + ans
	else:
		if carry:
			ans = str(carry) + ans
	return ans

def bigint_minus(a, b):
	a = str(a)
	b = str(b)
	M = []
	m = []
	sign = ''
	if len(a) > len(b) or (len(a) == len(b) and a >= b):
		[M, m] = [a, b]
	else:
		[M, m] = [b, a]
		sign = '-'
	m = '0' * (len(M) - len(m)) + m
	ans = ''
	borrow = 0
	for i in range(len(M)):
		s = int(M[-i - 1]) - int(m[-i - 1]) - borrow
		if s < 0:
			borrow = 1
			s += 10
		else:
			borrow = 0
		ans = str(s) + ans
	return sign + delete_head_zeros(ans)

def bigint_multiply(a, b):
	a = str(a)
	b = str(b)
	md = []
	for j in range(len(b)):
		carry = 0
		mj = ''
		for i in range(len(a)):
			m = int(a[-i - 1]) * int(b[-j - 1]) + carry
			carry = m // 10
			mj = str(m % 10) + mj
		else:
			if carry:
				mj = str(carry) + mj
		md.append(mj)
	ans = 0
	for k in range(len(md)):
		ans = bigint_plus(md[k] + '0' * k, ans)
	return ans

def bigint_divide(a, b, d=0):
	a = str(a)
	b = str(b)
	d = int(d)
	if d < 0:
		d = 0
	ans = ''
	r = ''
	for i in range(len(a) + d):
		q = 0
		if i < len(a):
			r += a[i]
		elif i == len(a):
			ans += '.'
			r += '0'
		else:
			r += '0'
		if bigint_compare(r, b) == -1:
			ans += str(q)
		else:
			while bigint_compare(r, b) >= 0:
				r = bigint_minus(r, b)
				q += 1
			ans += str(q)
	return delete_head_zeros(ans)

def main():
	(N, X) = input().split(' ')
	layer = [1]
	patties = [1]
	for i in range(int(N)):
		layer.append(bigint_plus(bigint_multiply(layer[-1], 2), 3))
		patties.append(bigint_plus(bigint_multiply(patties[-1], 2), 1))

	def count_patty(L, Y, P):
		if L == 0:
			return bigint_plus(P, 1)
		center = bigint_divide(bigint_plus(layer[L], 1), 2)
		if Y == '1':
			return P
		elif Y == layer[L]:
			return bigint_plus(P, patties[L])
		elif bigint_compare(Y, center) == 0:
			return bigint_plus(bigint_plus(P, 1), patties[L - 1])
		elif bigint_compare(Y, center) == 1:
			return count_patty(L - 1, bigint_minus(Y, center), bigint_plus(bigint_plus(P, patties[L - 1]), 1))
		elif bigint_compare(Y, center) == -1:
			return count_patty(L - 1, bigint_minus(Y, 1), P)
	print(count_patty(int(N), X, '0'))
main()


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)


def pat(n, x):
	if x == 0:
		return 0
	if n == 0:
		return 1
	a = 2 ** (n + 2) - 3
	if a // 2 + 1 <= x:
		return 2 ** n + pat(n - 1, x - a // 2 - 1)
	elif a // 2 == x:
		return 2 ** n - 1
	else:
		return pat(n - 1, x - 1)
(n, x) = map(int, input().split())
print(pat(n, x))


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

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


(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)


(n, x) = map(int, input().split())
f_dict = {0: 1}

def f(n):
	if f_dict.get(n):
		return f_dict.get(n)
	return 3 + f(n - 1) * 2
patty_dict = {0: 1}

def total_patty(n):
	if patty_dict.get(n):
		return patty_dict.get(n)
	return 1 + 2 * total_patty(n - 1)

def count_patty(n, x):
	if n == 0 and x == 1:
		return 1
	elif x == 0:
		return 0
	elif 1 <= x and x <= f(n - 1) + 1:
		return count_patty(n - 1, x - 1)
	elif x == f(n - 1) + 2:
		return total_patty(n - 1) + 1
	elif f(n - 1) + 2 <= x and x <= 2 * f(n - 1) + 2:
		return total_patty(n - 1) + 1 + count_patty(n - 1, x - f(n - 1) - 2)
	else:
		return total_patty(n)
print(count_patty(n, x))


(N, X) = map(int, input().split())
ans = 0
f = 0
for i in range(N, 1, -1):
	center = 2 * pow(2, i) - 1
	if X > center:
		X -= center
		ans += pow(2, i)
	elif X == center:
		ans += pow(2, i)
		f = 1
		break
	elif X < center:
		X -= 1
if f == 0:
	ans += 'BQQQB'[:X].count('Q')
print(ans)


(n, x) = (int(i) for i in input().split())

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


(N, X) = map(int, input().split())
burger = [(1, 0)]
prev = (1, 0)
for i in range(N):
	burger.append((2 * prev[0] + 1, 2 * prev[1] + 2))
	prev = burger[-1]
lev = N
cur = X - 1
ps = 0
for i in range(N + 1):
	if lev == 0:
		ps += 1
		break
	if cur == 0:
		break
	elif cur == sum(burger[lev - 1]) + 1:
		ps += burger[lev - 1][0] + 1
		break
	elif cur == sum(burger[lev]) - 1:
		ps += 2 * burger[lev - 1][0] + 1
		break
	if cur < sum(burger[lev]) / 2:
		cur -= 1
		lev -= 1
	else:
		ps += burger[lev - 1][0] + 1
		cur -= sum(burger[lev - 1]) + 2
		lev -= 1
print(ps)


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) = list(map(int, input().split(' ')))
level2p = [1] * (N + 1)
level2pb = [1] * (N + 1)
for i in range(N):
	level2p[i + 1] = level2p[i] * 2 + 1
	level2pb[i + 1] = level2pb[i] * 2 + 3

def dfs(n, x):
	if n == 0:
		return 1
	if x <= 1:
		return 0
	elif x <= 1 + level2pb[n - 1]:
		return dfs(n - 1, x - 1)
	elif x <= 1 + level2pb[n - 1] + 1:
		return level2p[n - 1] + 1
	elif x <= 1 + level2pb[n - 1] + 1 + level2pb[n - 1]:
		return level2p[n - 1] + 1 + dfs(n - 1, x - 1 - level2pb[n - 1] - 1)
	else:
		return level2p[n]
print(dfs(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())

def ABC115D(n, x):
	if x == 0:
		return 0
	if n == 0:
		return 1
	elif x == 1:
		return 0
	elif x >= 2 ** (n + 1) - 1:
		return ABC115D(n - 1, x - 2 ** (n + 1) + 1) + 2 ** n
	else:
		return ABC115D(n - 1, x - 1)
print(ABC115D(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())
eat = 0

def eat(n, x):
	if x == 0:
		return 0
	elif n == 0:
		return 1
	elif 2 ** (n + 2) - 3 <= x:
		return 2 ** (n + 1) - 1
	elif 2 ** (n + 2) - 3 > x and 2 ** (n + 1) - 1 <= x:
		return 2 ** n - 1 + 1 + eat(n - 1, x - (2 ** (n + 1) - 1))
	else:
		return eat(n - 1, x - 1)
print(eat(N, X))


(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))


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

def bug(l, y):
	if l == 0:
		return 0 if y <= 0 else 1
	mid = (h[l] + 1) // 2
	if y < mid:
		return bug(l - 1, y - 1)
	elif y == mid:
		return p[l - 1] + 1
	elif y > mid:
		return p[l - 1] + 1 + bug(l - 1, y - mid)
print(bug(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))


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

def p_eat(N, X):
	if X == 0:
		return 0
	elif X == bn[N]:
		return pn[N]
	elif bn[N - 1] + 1 < X:
		return pn[N - 1] + 1 + p_eat(N - 1, X - bn[N - 1] - 2)
	else:
		return p_eat(N - 1, X - 1)
print(p_eat(N, X))


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

def level_n_putty(n):
	if n == 0:
		return 1
	else:
		return 2 * level_n_putty(n - 1) + 1

def level_n_hb(n):
	if n == 0:
		return 1
	else:
		return 2 * level_n_hb(n - 1) + 3
m = level_n_hb(n)
s = 0
base = 0
while True:
	if x == base + 1:
		if n == 0:
			s += 1
		break
	elif x == base + m:
		s += level_n_putty(n)
		break
	else:
		l = level_n_hb(n - 1)
		if x < base + l + 2:
			base += 1
			n -= 1
			m = l
		elif x == base + l + 2:
			s += 1 + level_n_putty(n - 1)
			break
		else:
			base = base + l + 2
			s += 1 + level_n_putty(n - 1)
			n -= 1
			m = l
print(s)


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())
burger = [2 ** (i + 2) - 3 for i in range(n)]
burger2 = [2 ** (i + 1) - 1 for i in range(n)]
num = [0 for i in range(n)]
ans = 0
temp = n - 1
while x > 0:
	if x >= 1:
		x -= 1
	else:
		continue
	if x >= burger[temp]:
		num[temp] += 1
		x -= burger[temp]
	else:
		temp -= 1
		continue
	if x >= 1:
		ans += 1
		x -= 1
	else:
		continue
	if x >= burger[temp]:
		num[temp] += 1
		x -= burger[temp]
	else:
		temp -= 1
		continue
	if x >= 1:
		x -= 1
	else:
		continue
for i in range(n):
	ans += burger2[i] * num[i]
print(ans)


(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 count(N, X):
	if N == 0:
		return 1
	if X == 1:
		return 0
	elif 1 < X < 2 ** (N + 1) - 1:
		return count(N - 1, X - 1)
	elif X == 2 ** (N + 1) - 1:
		return 2 ** N
	elif 2 ** (N + 1) - 1 < X:
		return 2 ** N + count(N - 1, X - 2 ** (N + 1) + 1)
print(count(N, X))


(n, x) = map(int, input().split())
tp = 0
for i in range(n):
	ct = (2 ** (n - i + 2) - 4) // 2 + 1
	if x == 0:
		break
	if i == n - 1:
		tp += 'bpppb'[:x].count('p')
	else:
		pn = 2 ** (n - i) - 1
		if x < ct:
			x -= 1
		elif x >= ct:
			tp += pn + 1
			if x == ct:
				break
			x -= ct
print(tp)


(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))


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

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

def resolve():
	(N, X) = LI()
	X -= 1
	l = [0] * (N + 1)
	l[0] = 1
	for i in range(N):
		l[i + 1] = 2 * l[i] + 3
	p = [0] * (N + 1)
	p[0] = 1
	for i in range(N):
		p[i + 1] = 2 * p[i] + 1

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

def __starting_point():
	resolve()
__starting_point()


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


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

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


(n, x) = map(int, input().split())
l = [[1, 1], [5, 3]]
for i in range(2, n):
	a = l[-1][0]
	b = l[-1][1]
	l.append([a * 2 + 3, b * 2 + 1])
ans = 0
for i in range(n - 1, 0, -1):
	if x >= l[i][0] + 2:
		ans += l[i][1] + 1
		x -= l[i][0] + 2
	else:
		x -= 1
if x > 0:
	b = [0, 1, 1, 1, 0]
	ans += b[:x].count(1)
print(ans)


(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))


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

def func(m, y):
	if y == 0:
		return 0
	ret = 0
	t = 4 * pow(2, m) - 3
	if y >= t - 1:
		ret = pow(2, m + 1) - 1
	elif y == (t - 1) // 2:
		ret = pow(2, m) - 1
	elif y == (t - 1) // 2 + 1:
		ret = pow(2, m)
	elif y > (t - 1) // 2 + 1:
		ret = pow(2, m)
		ret += func(m - 1, y - (t - 1) // 2 - 1)
	else:
		ret = func(m - 1, y - 1)
	return ret
print(func(n, x))


printn = lambda x: print(x, end='')
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)

def f(n, x):
	nonlocal h
	if x > 2 ** (n + 2) - 3:
		x = 2 ** (n + 2) - 3
	if (n, x) in h:
		return h[n, x]
	ret = -1
	if n == 0:
		ret = x
	elif x <= 1:
		ret = 0
	elif x <= 2 ** (n + 1) - 2:
		ret = f(n - 1, x - 1)
	elif x == 2 ** (n + 1) - 1:
		ret = 2 ** n
	elif x <= 2 ** (n + 2) - 4:
		ret = 2 ** n + f(n - 1, x - 2 ** (n + 1) + 1)
	else:
		ret = 2 ** (n + 1) - 1
	h[n, x] = ret
	return ret
(n, x) = inm()
h = {}
print(f(n, x))


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

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


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)


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

def burger(N, X):
	if N == 0 and X == 1:
		return 1
	if X == 0:
		return 0
	twopow = pow(2, N)
	if X == 4 * twopow - 3:
		return 2 * twopow - 1
	if X > 2 * twopow - 2:
		return twopow + burger(N - 1, X - 2 * twopow + 1)
	elif X <= 2 * twopow - 2:
		return burger(N - 1, X - 1)
print(burger(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()))

	@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)


p = [1]
b = [1]
for i in range(50):
	p.append(p[i] * 2 + 1)
	b.append(b[i] * 2 + 3)

def main(n, x):
	if n == 0:
		if x == 1:
			return 1
		return 0
	if b[n] == x:
		return p[n]
	if b[n - 1] + 1 >= x:
		return main(n - 1, x - 1)
	else:
		return main(n - 1, x - b[n - 1] - 2) + 1 + p[n - 1]
(n, x) = map(int, input().split())
print(main(n, x))


def count(n, x):
	b1 = 1 << n
	b2 = b1 << 1
	return 1 if n == 0 else 0 if x == 1 else count(n - 1, x - 1) if x < b2 - 1 else b1 if x == b2 - 1 else count(n - 1, x + 1 - b2) + b1
(N, X) = map(int, input().split())
print(count(N, X))


(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))


3
from collections import defaultdict
(N, X) = (int(x) for x in input().split())
memo = {}

def size_lv(lv):
	if lv == 0:
		return 1
	if lv not in memo:
		memo[lv] = size_lv(lv - 1) * 2 + 3
	return memo[lv]
memo2 = {}

def num_pty(lv, X):
	if (lv, X) in memo2:
		return memo2[lv, X]
	if X == 0:
		return 0
	if lv == 0:
		memo2[lv, X] = 1
		return memo2[lv, X]
	prevSize = size_lv(lv - 1)
	if X <= prevSize + 1:
		memo2[lv, X] = num_pty(lv - 1, X - 1)
		return memo2[lv, X]
	if X == prevSize + 2:
		memo2[lv, X] = num_pty(lv - 1, prevSize) + 1
		return memo2[lv, X]
	memo2[lv, X] = num_pty(lv - 1, prevSize) + 1 + num_pty(lv - 1, min(X - prevSize - 2, prevSize))
	return memo2[lv, X]
print(num_pty(N, X))


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

def p(n):
	return 2 * 2 ** n - 1

def f(n):
	return 4 * 2 ** n - 3
c = 0
for i in range(n, 0, -1):
	if x:
		x -= 1
	if x >= f(i - 1):
		x -= f(i - 1)
		c += p(i - 1)
		if x:
			x -= 1
			c += 1
			if x >= f(i - 1):
				x -= f(i - 1)
				c += p(i - 1)
				if x:
					x -= 1
print(c)


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

def pans(l, x):
	if l == 1:
		return list('BPPPB'[:x]).count('P')
	elif x <= L[l - 2] + 1:
		return pans(l - 1, x - 1)
	else:
		return P[l - 2] + 1 + pans(l - 1, x - (2 + L[l - 2]))
print(pans(N, X))


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


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

def cal(n, x):
	if n == 0:
		return 1
	if x == 1:
		return 0
	ll = 2 ** (n + 1) - 3
	if x <= ll + 1:
		return cal(n - 1, x - 1)
	if x == ll + 2:
		return cal(n - 1, x - 2) + 1
	if x <= ll + ll + 2:
		return cal(n - 1, ll) + 1 + cal(n - 1, x - ll - 2)
	if x == ll + ll + 3:
		return 2 ** (n + 1) - 1
print(cal(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))


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

def rec(level, K):
	if level == 0:
		return 1
	if K == 1:
		return 0
	elif K <= L[level - 1] + 1:
		return rec(level - 1, K - 1)
	elif K == L[level - 1] + 2:
		return S[level - 1] + 1
	elif K <= L[level - 1] * 2 + 2:
		return rec(level - 1, K - L[level - 1] - 2) + S[level - 1] + 1
	else:
		return S[level - 1] * 2 + 1
print(rec(N, X))


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

def A(x):
	return pow(2, x + 2) - 3

def P(x):
	return pow(2, x + 1) - 1

def f(n, x):
	if n == 0:
		return 1
	if n == 1:
		return min(x - 1, 3)
	if x <= n:
		return 0
	if A(n) // 2 + 1 == x:
		return P(n - 1) + 1
	if A(n) == x:
		return P(n)
	if A(n) // 2 >= x:
		return f(n - 1, x - 1)
	return P(n - 1) + 1 + f(n - 1, x - A(n) // 2 - 1)
print(f(N, X))


def main():
	(N, X) = list(map(int, input().split()))
	nums = [None] * (N + 1)
	pnums = [None] * (N + 1)
	nums[0] = 1
	pnums[0] = 1
	for i in range(N):
		nums[i + 1] = nums[i] * 2 + 3
		pnums[i + 1] = pnums[i] * 2 + 1
	ans = 0
	while N >= 0:
		if N == 0:
			print(ans + 1)
			break
		if X == 1:
			print(ans)
			break
		elif X <= nums[N - 1] + 1:
			X -= 1
			N -= 1
		elif X == nums[N - 1] + 2:
			print(ans + pnums[N - 1] + 1)
			break
		elif X < nums[N]:
			X -= nums[N - 1] + 2
			ans += pnums[N - 1] + 1
			N -= 1
		else:
			print(ans + pnums[N])
			break

def __starting_point():
	main()
__starting_point()


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

def func(n, x):
	if n == 1:
		return 'BPPPB'[:min(x, 5)].count('P')
	else:
		ret = 0
		a = 2 ** n + 3 * (2 ** n - 1)
		if x >= a - n:
			return 2 ** (n + 1) - 1
		elif x > a // 2:
			return func(n - 1, x) + 1 + func(n - 1, x - a // 2 - 1)
		else:
			return func(n - 1, x - 1)
print(func(n, x))


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

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


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

def pNumber(level, number):
	if level == 0:
		return 1
	if number == 1:
		return 0
	if number <= burgerLengthList[level][0] // 2:
		return pNumber(level - 1, number - 1)
	elif number == burgerLengthList[level][0] // 2 + 1:
		return pNumber(level - 1, number - 1) + 1
	else:
		return burgerLengthList[level - 1][1] + 1 + pNumber(level - 1, number - burgerLengthList[level - 1][0] - 2)
print(pNumber(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))


import sys
sys.setrecursionlimit(10 ** 5)
(N, X) = map(int, input().split())
l = [1]
for i in range(N):
	l.append(2 * l[-1] + 3)
d = {}

def f(n, x):
	if (n, x) in d:
		return d[n, x]
	if n == 0:
		ans = 1
	elif x == 1:
		ans = 0
	elif x <= l[n - 1] + 1:
		ans = f(n - 1, x - 1)
	elif x == l[n - 1] + 2:
		ans = f(n - 1, l[n - 1]) + 1
	elif x <= 2 * l[n - 1] + 2:
		ans = f(n - 1, l[n - 1]) + 1 + f(n - 1, x - l[n - 1] - 2)
	else:
		ans = 2 * f(n - 1, l[n - 1]) + 1
	d[n, x] = ans
	return ans
print(f(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()


def do(level, x):
	if x <= 0:
		return 0
	if level == 0:
		return 1
	res = 0
	x -= 1
	if x > j[level - 1]:
		x -= j[level - 1] + 1
		res += k[level - 1] + 1
	return res + do(level - 1, x)
(n, x) = map(int, input().split())
j = [1] + [0] * 50
k = [1] + [0] * 50
for i in range(1, n + 1):
	j[i] = j[i - 1] * 2 + 3
	k[i] = k[i - 1] * 2 + 1
res = 0
print(do(n, x))


(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) = map(int, input().split())
P = [1]
H = [1]
for i in range(1, 51):
	P.append(P[i - 1] * 2 + 1)
	H.append(H[i - 1] * 2 + 3)

def r(n, x):
	if x <= n:
		return 0
	if x == H[n]:
		return P[n]
	if x >= H[n - 1] + 2:
		return P[n - 1] + 1 + r(n - 1, x - H[n - 1] - 2)
	else:
		return r(n - 1, x - 1)
print(r(N, X))


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

def n_pati(l):
	val = 1
	for i in range(l):
		val = val * 2 + 1
	return val

def n_layer(l):
	val = 1
	for i in range(l):
		val = val * 2 + 3
	return val
SUM = 0
while 1:
	if N == 1:
		if X in [0, 1]:
			break
		elif X >= 2:
			SUM += min(3, X - 1)
			break
	L = n_layer(N)
	if X >= L // 2:
		SUM += n_pati(N - 1)
		X -= n_layer(N - 1) + 1
		if X == 0:
			break
		SUM += 1
		X -= 1
		if X == 0:
			break
		N -= 1
	else:
		X -= 1
		N -= 1
	if X in [0, 1]:
		break
print(SUM)


(nn, xx) = map(int, input().split())

def f(n, x):
	if x == 0:
		return 0
	if n == 0:
		return 1
	if x == 2 ** (n + 2) - 3:
		return 2 ** (n + 1) - 1
	b = 2 ** (n + 1) - 3
	u = min(b, max(0, x - 2 - b))
	l = min(x - 1, b)
	return f(n - 1, u) + (1 if x > b + 1 else 0) + f(n - 1, l)
print(f(nn, xx))


(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))


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

def get_whole_barger(n):
	return P[n]

def get_patty(n, x):
	if n == 0 or x == 0:
		return P[0]
	if B[n] == x:
		return P[n]
	if x <= 1:
		return 0
	if x <= 1 + B[n - 1]:
		return get_patty(n - 1, x - 1)
	if x <= 2 + B[n - 1]:
		return get_whole_barger(n - 1) + 1
	if x <= 2 + B[n - 1] * 2:
		return get_whole_barger(n - 1) + 1 + get_patty(n - 1, x - 2 - B[n - 1])
	else:
		return get_whole_barger(n - 1) + 1 + get_whole_barger(n - 1)
print(get_patty(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))


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

def f(n, x):
	if x == 1 and n == 0:
		return 1
	if x == 1:
		return 0
	if x == 2 ** (n + 2) - 3:
		return 2 ** (n + 1) - 1
	if x == 2 ** (n + 1) - 1:
		return 2 ** n
	res = 0
	if 1 < x < 2 ** (n + 1) - 1:
		res = f(n - 1, x - 1)
		return res
	if 2 ** (n + 1) - 1 < x < 2 ** (n + 2) - 3:
		res = 2 ** n + f(n - 1, x - 2 ** (n + 1) + 1)
		return res
print(f(N, X))


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

def dfs(n, x):
	if burger_size[n] == x:
		return patty_num[n]
	if x == 1:
		return 0
	elif 1 < x <= 1 + burger_size[n - 1]:
		return dfs(n - 1, x - 1)
	elif x == 1 + burger_size[n - 1] + 1:
		return patty_num[n - 1] + 1
	elif 1 + burger_size[n - 1] + 1 < x < burger_size[n]:
		return patty_num[n - 1] + 1 + dfs(n - 1, x - burger_size[n - 1] - 2)
print(dfs(N, X))


import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter, defaultdict, deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
mod = 10 ** 9 + 7

def inp():
	return int(input())

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

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

def inpls():
	return list(input().split())

def inplm(n):
	return list((int(input()) for _ in range(n)))

def inplL(n):
	return [list(input()) for _ in range(n)]

def inplT(n):
	return [tuple(input()) for _ in range(n)]

def inpll(n):
	return [list(map(int, input().split())) for _ in range(n)]

def inplls(n):
	return sorted([list(map(int, input().split())) for _ in range(n)])
(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))


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))


import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().strip()
NI = lambda : int(input())
NMI = lambda : map(int, input().split())
NLI = lambda : list(NMI())
SI = lambda : input()

def make_grid(h, w, num):
	return [[int(num)] * w for _ in range(h)]

def main():
	(N, X) = NMI()
	A = [1]
	P = [1]
	for i in range(N):
		A.append(A[-1] * 2 + 3)
		P.append(P[-1] * 2 + 1)

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

def __starting_point():
	main()
__starting_point()


def solve(N, X):
	layer = [1]
	pate = [1]
	for _ in range(N):
		layer.append(layer[-1] * 2 + 3)
		pate.append(pate[-1] * 2 + 1)

	def burger(n, l):
		if layer[n] <= l:
			return pate[n]
		if l == 0:
			return 0
		re = 0
		if layer[n] // 2 + 1 <= l:
			re += pate[n - 1] + 1
			l -= layer[n] // 2 + 1
		else:
			l -= 1
		re += burger(n - 1, l)
		return re
	print(burger(N, X))

def __starting_point():
	(N, X) = list(map(int, input().split()))
	solve(N, X)
__starting_point()


(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))