import sys
sys.setrecursionlimit(10000)
S = input()


def pre_remove(s, i):
    '''
    101 -> 1
    010 -> 0
    この並びの場合は順番にかかわらず削除しても良い
    0011 -> 01
    1100 -> 10
    この並びの時は順番にかかわらず短縮しても良い
    '''
    cs = s
    ci = i
    while True:
        find_101 = cs.find('101')
        find_010 = cs.find('010')
        find_1100 = cs.find('1100')
        find_0011 = cs.find('0011')
        if find_101 > 0:
            cs = remove_target_point(cs, find_101)
            ci += 2
        elif find_010 > 0:
            cs = remove_target_point(cs, find_010)
            ci += 2
        elif find_1100 > 0:
            cs = remove_target_point(cs, find_1100 + 1)
            ci += 2
        elif find_0011 > 0:
            cs = remove_target_point(cs, find_0011 + 1)
            ci += 2
        else:
            return (cs, ci)

def search_removable_point(s):
    return [i for i, (i1, i2) in enumerate(zip(s[:-1], s[1:])) if i1 != i2]

def remove_target_point(s, i):
    return s[:i] + s[i+2:]

def max_removed_point(s, i):
    removable_points = search_removable_point(s)
    if removable_points:
        return max([
            max_removed_point(remove_target_point(s, point), i + 2)
            for point in removable_points
        ])
    else:
        return i

S_2, i_2 = pre_remove(S, 0)
print(max_removed_point(S_2, i_2))
