local n, x = io.read("*n", "*n")
n = n + 1
local len, pat = {1}, {1}
for i = 2, n do
  len[i] = len[i - 1] * 2 + 3
  pat[i] = pat[i - 1] * 2 + 1
end
local total_pat = 0
for i = n, 2, -1 do
  if x == 1 then
    x = 0
    break
  elseif x == len[i] then
    total_pat = total_pat + pat[i]
    x = 0
    break
  elseif x < (len[i] + 1) // 2 then
    x = x - 1
  elseif x == (len[i] + 1) // 2 then
    total_pat = total_pat + 1 + pat[i - 1]
    x = 0
    break
  else
    total_pat = total_pat + 1 + pat[i - 1]
    x = x - len[i - 1] - 2
  end
end
if x ~= 0 then total_pat = total_pat + 1 end
print(total_pat)
