s = input()
n = len(s)

left = 0
right = n
while right > left + 1:
    opt = (left + right) // 2
    tmp = 0  # 0の個数 - 1の個数
    for i in range(n):
        if s[i] == '0': tmp += 1
        elif s[i] == '1': tmp -= 1
        else:
            if tmp > 0: tmp -= 1
            else: tmp += 1
        
        if abs(tmp) > opt:
            break
    else:
        right = opt
        continue
    left = opt

print(right)
