N,X=gets.split.map(&:to_i)
def getn(dim)
  if dim==0 then return 1
  else return 2**(dim+2)-3 end
end
def getallp(dim)
  if dim==0 then return 1
  else return 2**(dim+1)-1 end
end
def getp(dim,num)
  if dim==0 then return 1 end
  if num<dim then return 0 end
  if num==getn(dim-1)+1 then return getallp(dim-1)+1 end
  if getn(dim-1)+1>num then
    return getp(dim-1,num-1)
  else
    return getallp(dim-1)+1+getp(dim-1,num-getn(dim-1)-2)
  end
end
p getp(N,X-1)