N,X = $stdin.readline.split.map(&:to_i)

def num_patties(l)
  l == 0 ? 1 : num_patties(l-1)*2+1
end

def num_layers(l)
  l == 0 ? 1 : num_layers(l-1)*2+3
end

def num_patties_upto(lev,x)
  if lev == 0
    x > 0 ? 1 : 0
  else
    nl = num_layers(lev)
    nh = num_layers(lev-1)
    if x <= 1
      0
    elsif x <= (1+nh)
      num_patties_upto(lev-1,x-1)
    elsif x == (2+nh)
      num_patties(lev-1)+1
    elsif x <= (2+nh+nh)
      num_patties(lev-1)+1+num_patties_upto(lev-1,x-1-nh-1)
    else
      num_patties(lev)
    end
  end
end

puts num_patties_upto(N,X)
#pp num_patties(N), num_layers(N), num_patties_upto(N,X)
