import itertools

S = input()
T = S
T_list=[]
#'?'のインデックス
indexes =[i for i, x in enumerate(T) if x=='?']
#print(indexes)

#?を全探索
nlist = itertools.product(['0','1'],repeat=len(indexes))
#print(nlist)
for n in nlist:
  T=S
  #print(n)
  for j in range(len(indexes)):
    T = T.replace('?',n[j],1)
  T_list.append(T)

def vmax(T):
  vmax=0
  v=0
  for l in range(len(T)-1):
    for r in range(l+1,len(T)):
      v = abs(T[l:r+1].count('0')-T[l:r+1].count('1'))
      if v >= vmax:
        vmax =v
  return vmax

m =10**10
x =0
for t in T_list:
  x =vmax(t)
  if x < m:
    m = x
print(m)