S = input()

n = len(S)
S = S+'2'
dp = [0]*(n+1)
last0 = 0
last1 = 0
for i in range(1, n+1):
  if S[i-1] == '0':
    last0 += 1
    a = abs(dp[i-1] + 1)
    b = last0
    if a >= b:
      dp[i] = dp[i-1] + 1
    else:
      dp[i] = b
    last1 = 0
  elif S[i-1] == '1':
    last1 += 1
    a = abs(dp[i-1] - 1)
    b = last1
    if a >= b:
      dp[i] = dp[i-1] - 1
    else:
      dp[i] = -b
    last0 = 0
  else:
    if dp[i-1] >= 0:
      last1 += 1
      a = abs(dp[i-1] - 1)
      b = last1
      if a >= b:
        dp[i] = dp[i-1] - 1
      else:
        dp[i] = -b
      last0 = 0
    elif dp[i-1] < 0:
      last0 += 1
      a = abs(dp[i-1] + 1)
      b = last0
      if a >= b:
        dp[i] = dp[i-1] + 1
      else:
        dp[i] = b
      last1 = 0
  if i>3 and dp[i-2]<0 and dp[i-1] == 2 and dp[i] == 1 and S[i] == '0':
    dp[i] = -1
  elif i>3 and dp[i-2]>0 and dp[i-1] == -2 and dp[i] == -1 and S[i] == '1':
    dp[i] = 1
print(max(map(abs, dp)))