
S= input()

TmpS = list(S)
oneSize = len(S.replace('0','').replace('?',''))
zeroSize = len(S.replace('1','').replace('?',''))

zeroCount = 0
oneCount = 0
resCount = 0
res=1
tmp = ''
for i in range(len(TmpS)):
    if TmpS[i] == '1':
        oneCount += 1
    elif TmpS[i] == '0':
        zeroCount += 1
    else:
        sizeDiff =abs(oneSize - zeroSize)
        countDiff =abs(oneCount - zeroCount)
        if sizeDiff == 0 and countDiff == 0:
            if tmp == '1' or (i<len(TmpS)-1 and TmpS[i+1]=='1'):
                TmpS[i] = '0'
                zeroCount += 1
                zeroSize += 1
            else:
                TmpS[i] = '1'
                oneCount += 1
                oneSize += 1

        else:
            tmpOne = oneSize if sizeDiff > countDiff else oneCount
            tmpZero = zeroSize if sizeDiff > countDiff else zeroCount
            if tmpOne > tmpZero:
                TmpS[i] = '0'
                zeroCount += 1
                zeroSize += 1
            else:
                TmpS[i] = '1'
                oneCount += 1
                oneSize += 1

    if tmp == TmpS[i]:
        resCount += 1
        if resCount > res:
            res = resCount
    else:
        resCount = 1
    tmp = TmpS[i]

print(res)