import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



# 目標の文字を決める -> シミュレーション



import numpy as np



S = np.array(list(read().rstrip()))



def F(S,x):

    A = (S == x)

    t = 0

    while True:

        if np.all(A):

            return t

        A = (A[:-1] | A[1:])

        t += 1



answer = min(F(S,x) for x in set(S))

print(answer)
import sys

import numpy as np



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



S = np.array(list(read().rstrip().decode()))



def f(S, a):

    S = S == a

    if not np.any(S):

        return len(S)

    for n in range(len(S)):

        if np.all(S):

            return n

        S = S[1:] | S[:-1]



x = min(f(S, a) for a in S)

print(x)
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 目標の文字を決める -> シミュレーション
import numpy as np

S = np.array(list(read().rstrip()))


def F(S, x):
    A = S == x
    t = 0
    while True:
        if np.all(A):
            return t
        A = A[:-1] | A[1:]
        t += 1


answer = min(F(S, x) for x in set(S))
print(answer)

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = np.array(list(read().rstrip().decode()))


def f(S, a):
    S = S == a
    if not np.any(S):
        return len(S)
    for n in range(len(S)):
        if np.all(S):
            return n
        S = S[1:] | S[:-1]


x = min(f(S, a) for a in S)
print(x)

+import numpy as np -# 目標の文字を決める -> シミュレーション -import numpy as np - -S = np.array(list(read().rstrip())) +S = np.array(list(read().rstrip().decode())) -def F(S, x): -    A = S == x -    t = 0 -    while True: -        if np.all(A): -            return t -        A = A[:-1] | A[1:] -        t += 1 +def f(S, a): +    S = S == a +    if not np.any(S): +        return len(S) +    for n in range(len(S)): +        if np.all(S): +            return n +        S = S[1:] | S[:-1] -answer = min(F(S, x) for x in set(S)) -print(answer) +x = min(f(S, a) for a in S) +print(x)