import random

s_ori=input()
cycle=10000
unb=[0]*2000 ##(len(s_ori)*(len(s_ori)+1)//2)
zero=0
one=0
ans=1000000
un=0
s=s_ori
ran=0


for a in range(cycle):
  s=s_ori
  s=list(s)
  for i in range(len(s)):
    if s[i]=='?':
      s[i]=random.randrange(2)
  s=list(map(int,s))
  for j in range(len(s)//2):
    for k in range(len(s)//2,len(s)):
      if j==k:
        unb[len(s)*j+k]=0
      else:
        zero=s[j:k].count(0)
        one=s[j:k].count(1)
        unb[len(s)*j+k]=abs(zero-one)
  un=max(unb)
  if un<ans:
    ans=un
    
print(ans)