from sys import stdin

mem = {}
total_len = -1
current_mins = [50] * 50
result = -1

def solve(line, relocations):
	#print('depth', relocations)
	global mem, total_len, current_mins, result
	for i in range(relocations+1):
		if current_mins[i] < relocations:
			return current_mins[i]
	if relocations > total_len:
		return total_len
	elif line == result:
		return relocations
	elif line in mem:
		return mem[line]
	else:
		shifts = [[0, i] for i in range(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][0] += 1
		shifts.sort(key=lambda x: x[0])
		shifts.reverse()
		for i, shift in enumerate(shifts):
			if shift[0] > 0:
				new_line = line | line>>shift[1]
				min_relocations = min(min_relocations, solve(new_line, relocations + 1))
				current_mins[relocations] = 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))
	
