n, x = gets.split.map(&:to_i) # 整数半角区切り,非配列
#arys = []; n.times { arys << gets.chomp.split.map(&:to_i).to_a }  # 整数半角区切り,複数行
# strings = []; 2.times {strings << gets.chomp} # 文字列複数受け取り

@ans = 0

def pn(n)
 (2 **(n+1)) -1
end

def loopn(n,x)
	if (n==1)
	    case x
			when 1    then return 0
			when 2..4 then return x-1
			when 5    then return 3
			else           return 0
		end
	end

	s = pn(n)

	case x
		when s       then return pn(n-1)+1
		when s-1     then return pn(n-1)
		when 0...s-1 then return loopn(n-1, x-1)
		when s*2 -1  then return s
		else              return pn(n-1) + loopn(n-1, x-s) + 1
	end
end

p loopn(n,x)