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