z=0
n=0
s=input()
fz=s.count("0")
fo=s.count("1")

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 fz>fo:
				n+=1
				fo+=1
			else:	
				z+=1
				fz+=1
	l.append(abs(z-n))
print(max(l))		