# 3
# 111 011 001 000 100 110 -> 36
# 010 101 -> 2

N = gets.to_i
X = gets.to_i(2)

upper_bit = 2**(N-1)

ret = Array.new(X+1)

class Node
    attr_accessor :num
end

while !ret.select{|e| e==nil }.empty? do
    target_index = ret.index(nil)
    node = Node.new
    ret[target_index] = node
    ctn = 1
    next_index = target_index.odd? ? target_index/2 : target_index/2 + upper_bit
    while target_index != next_index do
        ret[next_index] = node if next_index <= X
        ctn+=1
        next_index = next_index.odd? ? next_index/2 : next_index/2 + upper_bit
    end
    node.num = ctn
end

puts ret.map{|e| e.num}.inject(:+)

