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