n1,n2 = gets.chomp.split(" ").map(&:to_i)
count = n1
ans = 0
count2 = 0
while count > 0
  if n2 >= 2**(count+1) - 1 + count2
    n2 -= 2**(count+1) - 1 + count2
    ans += 2**count
    count2 = 0
  else
    count2 += 1
  end
  count -= 1
end
if n2 >= 5
  ans += 3
elsif n2 == 0
else
  ans += n2 - 1
end
p ans
