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 s[i-1]=="1":
				z+=1
			elif s[i-1]=="?":
				t1=s[max(l):i].count("1")
				t2=s[max(l):i].count("0")
				if t1>=t2:
					z+=1
				else:
					n+=1
			else:
				n+=1
	
	l.append(abs(z-n))
print(max(l))		