s=input()
qus=s.count("?")
zeros=s.count("0")
ones=s.count("1")
result=abs(zeros-ones)
if qus%2 ==1:
  result+= -1
max1=1
max2=0
last=""
for subs in s:
  if subs == "?":
    max1=1
    last=""
    continue
  if last == subs:
    max1+=1
  else:
    max1=1
    last=subs
  max2=max(max1,max2)
result=max(result,max2)
print(result)