sent = str(input())
def search(let):
    candi = []
    for i in range(len(let) - 1):
        if let[i] != let[i+1]:
            ss = ""
            for j in range(i):
                ss += str(let[j])
            for j in range(i+2,len(let)):
                ss += let[j]
            if ss == "":
                print(len(sent))
                exit(0)
            candi.append(search(ss))
    if len(candi) == 0: ncan = [let]
    else:
        ncan = sorted(candi, key= lambda x: len(x))
    return ncan[0]

print(len(sent)-len(search(sent)))