import re
S = input()

match_101 = re.compile('101')
match_010 = re.compile('010')
match_1100 = re.compile('1100')
match_0011 = re.compile('0011')

def pre_remove(s, i):
    '''
    101 -> 1
    010 -> 0
    0011 -> 01
    1100 -> 10
    この並びの時は順番にかかわらず短縮しても良い
    '''
    cs = s
    prev_s = cs
    ci = i
    prev_ci = ci
    while True:
        cs = match_101.sub('1', cs)
        cs = match_010.sub('0', cs)
        cs = match_1100.sub('10', cs)
        cs = match_0011.sub('01', cs)
        cs = cs[2:] if cs.startswith('10') else cs
        cs = cs[2:] if cs.startswith('01') else cs
        cs = cs[:-2] if cs.endswith('10') else cs
        cs = cs[:-2] if cs.endswith('01') else cs
        ci += len(prev_s) - len(cs)
        if prev_ci == ci:
            return (cs, ci)
        prev_s = cs
        prev_ci = ci

#def search_removable_point(s):
#    if s.find('0') >= 0 and s.find('1') >= 0:
#        return [i for i, (i1, i2) in enumerate(zip(s[:-1], s[1:])) if i1 != i2]
#    else:
#        return []

# 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(i_2)
