s=list(input())
k=0
z=''
cou=[]
let=[]
for x in s:
    if z==x:
        cou[-1]+=1
    else:
        cou.append(1)
        let.append(x)
        z=x
from math import ceil
k=0
while len(let)>1:
    k+=1

    if len(let)>2:
        times=ceil(min(cou[-1]*2,cou[0]*2,min(cou[1:-1]))/2)*2
    else:
        times=min(cou[1],cou[0])*2
    cou[0]-=times//2
    cou[-1]-=times//2
    for i in range(1,len(let)-1):
        cou[i]-=times
    i=0
    while i<len(let):
        if cou[i]<=0:
            cou.pop(i)
            let.pop(i)
            try:
                if let[i-1]==let[i]:
                    cou[i-1]+=cou[i]
                    cou.pop(i)
                    let.pop(i)
            except:
                continue
        else:
            i+=1
    #print(let)
    #print(cou)
print(k)