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 solve(s):
    groups = getgroups(s)
    ret = 0
    while len(groups) > 1:
        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:
                if new_groups == [] or new_groups[-1][0] != new_group[0]:
                    new_groups += [new_group]
                else:
                    new_groups[-1][1] += new_group[1]
        ret += 1
        groups = new_groups
    return ret


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