A binary expansion of an integer n is a sequence of "digits" akak−1…a1a0 that satisfies all three of the following conditions:
A single integer can have many different binary expansions. Among all of them, the ones with the fewest nonzero digits are called optimal. For example, writing −1 as 1 for convenience, the binary expansions of 15 include 10001, 1111, and 10011. The first one, 10001=16−1=15, has only 2 nonzero digits, so it is an optimal expansion of 15.
Write a program that, given an integer n, computes the number of nonzero digits in its optimal binary expansion.
The first line contains an integer r (1≤r≤500). The second line contains an integer n made up of r decimal digits. The number n is written starting from its most significant digit (that is, in the usual order) and begins with a nonzero digit.
Print, on a single line, the number of nonzero digits in the optimal binary expansion of n.