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