import sys
from collections import *
from string import *
from itertools import *

def f():
    global groups
    n = len(groups)
    mi = min(groups[0][1],groups[-1][0])
    
    for i in range(1,n-1):
        mi = min((groups[i][1]+1)/2,mi)
    
    for i in range(n):
        if i==0 or i==(n-1):
            groups[i][1] -= mi
        else:
            groups[i][1] -= 2*mi
    
    ngroups = []
    for i in range(n):
        if groups[i][1]>0:
            ngroups.append(groups[i])
    n = len(ngroups)    
    
    groups = []

    if not ngroups:
        return mi
    
    groups = [ngroups[0]]
    
    for i in range(1,n):
        if ngroups[i][0]==groups[-1][0]:
            groups[-1][1] +=  ngroups[i][1]
        else:
            groups.append(ngroups[i])
    
    return mi
    

     
s = raw_input()
groups = []
last = s[0]
freq = 0
for char in s:
    if char==last:
        freq+=1
    else:
        groups.append([last,freq])
        last = char
        freq = 1
groups.append([last,freq])
ans = 0
while len(groups)>1:
    ans += f()
#ans += f()
#print groups
print ans