s=input()

cnt0=0
cnt1=0
r=0
for c in s:
    if c == "0":
        cnt0+=1
    elif c == "1":
        cnt1+=1
    elif c == "?":
        if cnt0 > cnt1:
            cnt1 += 1
        else:
            cnt0 += 1

    r=max(r,abs(max(cnt0,cnt1)-min(cnt0,cnt1)))

print(r)