S = list(map(int,input()))
init = int(len(S))
ans = []

def cube(S,ans):
    if not any(S) or all(S):
        ans.append(int((init-len(S))))
    for i in range(len(S)-1):
        if S[i] != S[i+1]:
            cube(S[0:i]+S[i+2:],ans)
cube(S,ans)
ans.sort()
print(ans[-1])