def getgroups(s):
    ret = []
    i = 0
    while i < len(s):
        j = i
        while j < len(s) and s[i] == s[j]:
            j += 1
        ret += [[s[i], j - i]]
        i = j

    return ret


def mergegroups(groups):
    new_groups = []
    i = 0
    while i < len(groups):
        j = i
        total_cnt = 0
        while j < len(groups) and groups[i][0] == groups[j][0]:
            j += 1
            total_cnt += groups[i][1]

        new_groups += [[groups[i][0], total_cnt]]

        i = j
    return new_groups

def solve(s):
    groups = getgroups(s)
    ret = 0
    while groups:
        if len(groups) == 1:
            break
        new_groups = []
        for idx, group in enumerate(groups):
            new_group = [group[0], group[1]]
            if idx > 0:
                new_group[1] -= 1
            if idx + 1 < len(groups):
                new_group[1] -= 1

            if new_group[1] > 0:
                new_groups += [new_group]
        groups = mergegroups(new_groups)
        ret += 1
    return ret


s = raw_input()
print solve(s)
# print solve("aabb")
# print solve("aabcaa")