N,X = gets.split.map(&:to_i)
array = Array.new(50,"")
array[0] = "P"

=begin
sup = 1
count = 0
while X > sup
  sup = sup*2+3
  count += 1
end
=end

1.upto(N) do |i|
  array[i] = "B" + array[i-1] + "P" + array[i-1] + "B"
end
#puts count
=begin
N.times do |i|
puts array[i]
end
=end
puts array[N][0,X].count("P")
