z=0
n=0
s=input()
l=[]
for i in range(len(s)):
	if s[i]=="0":
		z+=1
	elif s[i]=="1":
		n+=1
	else:
		if z>n:
			n+=1
		elif z<n:
			z+=1
		else:
			if i<len(s)-1 and s[i+1]=="1":
				z+=1
			else:	
				n+=1
	l.append(abs(z-n))
print(max(l))		