s = input()
zero = 0
ones = 0
unbalance = 10**18
last = 0
mode = 0
maxlast = 0
for i in range(len(s)):
	if s[i] == "0":
		zero += 1
		if mode == 0:
			last += 1
		else:
			mode = 0
			last = 1
	elif s[i] == "1":
		ones += 1
		if mode == 1:
			last += 1
		else:
			mode = 0
			last = 1
	else:
		if ones > zero:
			zero += 1
			if mode == 0:
				last += 1
			else:
				mode = 0
				last = 1
		else:
			ones += 1
			if mode == 1:
				last += 1
			else:
				mode = 0
				last = 1
	maxlast = max(maxlast, last)
	unbalance = min(abs(zero-ones), unbalance)
print(max(unbalance, maxlast))