import functools

alpha = "abcdefghijklmnopqrstuvwxyz"

resultmap = {}

def replace(s:str):
    l = [(s.index(a) if a in s else -1,a) for a in alpha]
    l = [a for a in l if a[0] != -1]
    t = sorted(l,key=lambda k:k[0])
    # print(t)
    for bef,aft in [(c,alpha[i]) for i,c in t]:
        # print(bef,aft)
        s = s.replace(bef,aft)
    return s


def check(s):
    s = replace(s)
    if s in resultmap:
        return resultmap[s]
    # print(s)
    dict = {w: (False, -1, -1) for w in alpha}
    for i, c in enumerate(s):
        if dict[c][0]:
            dict[c] = (False, dict[c][1], dict[c][2])
        else:
            f = dict[c][1]
            dict[c] = (True, i if f == -1else f, i)

    # print(dict)
    aaaa = [c for c in alpha if dict[c][0]]
    # print(aaaa)

    if len(aaaa) <= 1:
        resultmap[s]=1
        return 1

    ser = sorted([dict[a][2] for a in aaaa])
    target1 = ser[1]
    ser = sorted([dict[a][1] for a in aaaa])
    target2 = ser[-2]
    # print(target1)
    # print(target2)
    r =  min((1 + check(s[target1:])),1+check(s[:target2+1]))
    resultmap[s]=r
    return r


    # return functools.reduce(lambda a, b: a + b, aaaa)


def main():
    n = check(input())
    print(max(1, n))


if __name__ == "__main__":
    main()
