

t = "abcdefghijklmnopqrstuvwxyz"

s = eval(input())

ans = 1000

for i in t:

    S = s

    c = 0

    while len(set(S))!=1:

        c+=1

        ts = ""

        for  j,k in zip(S,S[1:]):

            if j == i or k == i:

                ts+=i

            else:

                ts+=k

        S = ts

    ans = min(ans,c)

    # print(c)



print(ans)





# t = "abcdefghijklmnopqrstuvwxyz"

s = eval(input())

t = set(list(s))

ans = 1000

for i in t:

    S = s

    c = 0

    while len(set(S))!=1:

        c+=1

        ts = ""

        for  j,k in zip(S,S[1:]):

            if j == i or k == i:

                ts+=i

            else:

                ts+=k

        S = ts

    ans = min(ans,c)

    # print(c)



print(ans)





t = "abcdefghijklmnopqrstuvwxyz"
s = eval(input())
ans = 1000
for i in t:
    S = s
    c = 0
    while len(set(S)) != 1:
        c += 1
        ts = ""
        for j, k in zip(S, S[1:]):
            if j == i or k == i:
                ts += i
            else:
                ts += k
        S = ts
    ans = min(ans, c)
    # print(c)
print(ans)

# t = "abcdefghijklmnopqrstuvwxyz"
s = eval(input())
t = set(list(s))
ans = 1000
for i in t:
    S = s
    c = 0
    while len(set(S)) != 1:
        c += 1
        ts = ""
        for j, k in zip(S, S[1:]):
            if j == i or k == i:
                ts += i
            else:
                ts += k
        S = ts
    ans = min(ans, c)
    # print(c)
print(ans)

-t = "abcdefghijklmnopqrstuvwxyz" +# t = "abcdefghijklmnopqrstuvwxyz" +t = set(list(s))