S=input()

N = len(S)


if N == 1:
    print(1)
else:
    max = [-1,-1]
    tmpmax=-1
    cnt = 0
    maxpos= -1
    right=0
    rightmax=0
    left=0
    leftmax=0
    chk = ['0','1']

    for k in range(2):

        for i in range(N):
            if S[i] == chk[k]:
                cnt = cnt + 1
                if cnt > tmpmax:
                    tmpmax = cnt
                    maxpos = i
            else:
                cnt = 0

        for i in range(maxpos+1,N):
            if S[i] != chk[k]:
                right = right - 1
            else:
                right = right + 1
            if right > 0 and right > rightmax:
                rightmax = right

        for i in range(maxpos-tmpmax,-1,-1):
            if S[i] != chk[k]:
                left = left - 1
            else:
                left = left + 1
            if left > 0 and left > leftmax:
                leftmax = left

        if tmpmax == -1:
            max[k] = 1
        else:
            max[k] = tmpmax + rightmax + leftmax

    if max[0] > max[1]:
        max = max[0]
    else:
        max = max[1]
