S = input()

def pre_remove(s, i):
    '''
    101 -> 1
    010 -> 0
    この並びの場合は順番にかかわらず削除しても良い
    '''
    find_101 = s.find('101')
    find_010 = s.find('010')
    if find_101 > 0:
        return pre_remove(remove_target_point(s, find_101), i + 2)
    elif find_010 > 0:
        return pre_remove(remove_target_point(s, find_010), i + 2)
    else:
        return (s, i)

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))
