N, X = gets.split.map(&:to_i)

#レベルNバーガーを表す文字列を返す
def dfs(n)
  if n == 0
    return "P"
  end
  bg = dfs(n-1)
  return "B" + bg + "P" + bg + "B"
end

s = dfs(N)
ans = 0

X.times do |i|
  ans += 1 if s[i] == "P"
end

puts ans
