N, X = gets.chomp.split.map(&:to_i)
BAN = "B"
PAT = "P"

def n_1bargar(num)
  if num == 0
    PAT
  else
    BAN + n_1bargar(num - 1) + PAT + n_1bargar(num - 1) + BAN
  end
end

bargar = n_1bargar(N)

eat = bargar.slice(0, X)

puts eat.count(PAT)
