from sys import stdin mem = {} total_len = -1 current_min = 50 result = -1 def solve(line, relocations): #print('depth', relocations) global mem, total_len, current_min, result if relocations > total_len: return total_len elif relocations == current_min: return current_min elif line in mem: return mem[line] elif line == result: return relocations else: shifts = [0] * total_len min_relocations = 50 for i in range(total_len): if (1 << i) & line == 0: for j in range(i+1, total_len): if (1 << j) > 0: shifts[j-i] += 1 for i, shift in enumerate(shifts): if shift > 0: new_line = line | line>>i min_relocations = min(min_relocations, solve(new_line, relocations + 1)) if relocations == 0: current_min = min_relocations mem[line] = min_relocations return min_relocations #print('starting') line = stdin.readline().strip() if line[0] == '0': print(-1) else: total_len = len(line) result = (1 << total_len) - 1 num = 0 for char in line: if char == '1': num += 1 num*=2 num = int(num/2) print(solve(num, 0))