import re
S = input()

match_101 = re.compile('10(?=1)')
match_010 = re.compile('01(?=0)')
match_1100 = re.compile('1(1+0+)0')
match_0011 = re.compile('0(0+1+)1')

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('', cs)
        cs = match_010.sub('', 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
S_2, i_2 = pre_remove(S, 0)
print(i_2)
