input = input()
min = 10000000000000000
nums =['']
for c in input:
    newnums = []
    if c == "0" or c == "1":
        for i in range(len(nums)):
            newnums.append(nums[i] + c)
    else:
        for i in range(len(nums)):
            newnums.append(nums[i] + "0")
            newnums.append(nums[i] + "1")
    nums = newnums
for num in nums:
    gap = 0
    max = 0
    min = 0
    for c in num:
        if c == "0":
            gap += 1
            max = gap if gap > max else max
        elif c == "1":
            gap -=1
            min = gap if gap < min else min
    x = max-min
    min = x if x < min else min
min = 0 - min if min < 0 else min 
print(min)
 
    