inp = raw_input()
l = len(inp)
past = inp[0]
cnt = 1
dp = []
for i in xrange(1,l):
    if(inp[i]==past):
        cnt += 1
    else:
        dp +=[(cnt,past)]
        past = inp[i]
        cnt = 1
dp +=[(cnt,past)]
ans = 0
while(len(dp)>1):
    if(dp[0][0]!=1):
        temp = [(dp[0][0]-1,dp[0][1])]
    else:
        temp = []
    ans += 1
    for i in xrange(1,len(dp)-1):
        x = min(2,dp[i][0])
        if(x!=dp[i][0]):
            if(len(temp)==0 or temp[-1][-1]!=dp[i][1]):
                temp += [(dp[i][0]-x,dp[i][1])]
            else:
                temp[-1] = (temp[-1][0]+dp[i][0]-x,temp[-1][-1])
    i = len(dp)-1
    x = min(1,dp[i][0])
    if(x!=dp[i][0]):
        if(len(temp)==0 or temp[-1][-1]!=dp[i][1]):
            temp += [(dp[i][0]-x,dp[i][1])]
        else:
            temp[-1] = (temp[-1][0]+dp[i][0]-x,temp[-1][-1])
    dp = temp
print ans
