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=""
news=""
for subs in s:
  if subs == "?":
    if last=="0":
      news+="1"
    elif last =="1":
      news+="0"
    else:
      if len(news)>1:
        if news[-1]=="0":
          news+="1"
        else:
          news +="0"
      else:
        news += "1"
    max1=1
    last=subs
    continue
  news += subs
  if last == subs:
    max1+=1
  else:
    max1=1
    last=subs
"""  max2=max(max1,max2)  
result=max(result,max2)
zeros=news.count("0")
ones=news.count("1")
max2=abs(zeros-ones)
result=max(result,max2)
"""
#print(news)
max1=1
last=""
max2=0
for subs in news:
  if last == subs:
    max1+=1
  else:
    max1=1
    last=subs
  max2=max(max1,max2)  
result=max(result,max2)
print(result)