Signed Binary Expansion

No attempts yetTime limit1sMemory limit128 MB

Problem

A binary expansion of an integer nn is a sequence of "digits" akak1a1a0a_k a_{k-1} \ldots a_1 a_0 that satisfies all three of the following conditions:

  1. every digit a0,a1,,aka_0, a_1, \ldots, a_k is equal to 11, 00, or 1-1;
  2. the most significant digit aka_k is not zero;
  3. n=ak2k+ak12k1++a12+a0n = a_k \cdot 2^k + a_{k-1} \cdot 2^{k-1} + \cdots + a_1 \cdot 2 + a_0.

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-1 as 1\overline{1} for convenience, the binary expansions of 1515 include 100011000\overline{1}, 11111111, and 10011100\overline{1}1. The first one, 10001=161=151000\overline{1} = 16 - 1 = 15, has only 22 nonzero digits, so it is an optimal expansion of 1515.

Write a program that, given an integer nn, computes the number of nonzero digits in its optimal binary expansion.

Input

The first line contains an integer rr (1r5001 \le r \le 500). The second line contains an integer nn made up of rr decimal digits. The number nn is written starting from its most significant digit (that is, in the usual order) and begins with a nonzero digit.

Output

Print, on a single line, the number of nonzero digits in the optimal binary expansion of nn.