from collections import Counter

S=input()
l=len(S)
list=list(S)

def change(list):
  i=1
  while(i<l):
    if(list[i]=="?"):
       if(list[i-1]=="0"):
         list[i]="1"
       else:
         list[i]="0"
    i+=1

if(list[0]!="?"):
  change(list)
  c = Counter(list)
  print(abs(c["1"]-c["0"]))
else:
  slist=list

  list[0]=0
  change(list)

  slist[0]=1
  change(slist)

  c1 = Counter(list)
  c2 = Counter(slist)

  r1=abs(c1["1"]-c1["0"])
  r2=abs(c2["1"]-c2["0"])

  if(r1<r2):
    print(r1)
  else:
    print(r2)