# -*- coding: utf-8 -*-
from copy import copy
a = list(map(int,input()))
cur_min = 100001
def remove_max(cubes):
    global cur_min
    for i in range(len(cubes)-1):
        if cubes[i] != cubes[i+1]:
            z = copy(cubes)
            z.pop(i)
            z.pop(i)
            if len(z) == 0:
                cur_min=0
            if len(z) <= cur_min:
                cur_min = len(z)
                remove_max(z)
remove_max(a)
if cur_min==100001:
    print(0)
else:
    print(len(a) - cur_min)
