S = eval(input())

N = len(S)



from collections import Counter

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]



def check(arr):

    e = arr[0]

    return len(arr) == arr.count(e)





ans = float('inf')

for c in chars:

    SL = list(S)

    cnt = 0

    while not check(SL):

        for i, si in enumerate(SL):

            if i == 0:

                continue

            if si == c:

                SL[i-1] = c

        SL = SL[:-1]

        cnt += 1

        # print(SL)

    ans = min(ans, cnt)



print(ans)
S = eval(input())

N = len(S)



from collections import Counter

chars = [chr(i) for i in range(ord('a'), ord('z')+1)]



def check(arr):

    e = arr[0]

    return len(arr) == arr.count(e)





ans = float('inf')

for c in chars:

    cnt = 0

    t = S

    while not check(t):

        u = ''

        for i in range(len(t)-1):

            if t[i] == c or t[i+1] == c:

                u += c

            else:

                u += t[i]

        cnt += 1

        t = u

    ans = min(ans, cnt)



print(ans)
S = eval(input())
N = len(S)
from collections import Counter

chars = [chr(i) for i in range(ord("a"), ord("z") + 1)]


def check(arr):
    e = arr[0]
    return len(arr) == arr.count(e)


ans = float("inf")
for c in chars:
    SL = list(S)
    cnt = 0
    while not check(SL):
        for i, si in enumerate(SL):
            if i == 0:
                continue
            if si == c:
                SL[i - 1] = c
        SL = SL[:-1]
        cnt += 1
        # print(SL)
    ans = min(ans, cnt)
print(ans)

S = eval(input())
N = len(S)
from collections import Counter

chars = [chr(i) for i in range(ord("a"), ord("z") + 1)]


def check(arr):
    e = arr[0]
    return len(arr) == arr.count(e)


ans = float("inf")
for c in chars:
    cnt = 0
    t = S
    while not check(t):
        u = ""
        for i in range(len(t) - 1):
            if t[i] == c or t[i + 1] == c:
                u += c
            else:
                u += t[i]
        cnt += 1
        t = u
    ans = min(ans, cnt)
print(ans)

-    SL = list(S) -    while not check(SL): -        for i, si in enumerate(SL): -            if i == 0: -                continue -            if si == c: -                SL[i - 1] = c -        SL = SL[:-1] +    t = S +    while not check(t): +        u = "" +        for i in range(len(t) - 1): +            if t[i] == c or t[i + 1] == c: +                u += c +            else: +                u += t[i] -        # print(SL) +        t = u