# coding:utf-8



from collections import Counter





def inpl(): return list(map(int, input().split()))





S = eval(input())

C = Counter(S)

if len(S) == 1:

    print((0))

    exit()



ans = 100

for key in list(C.keys()):

    prev_S = list(S)

    cnt = 0

    t = len(S) - 1

    while t > 0:

        if all([1 if s == key else 0 for s in prev_S]):

            ans = min(ans, cnt)

            break

        SS = []

        for i in range(t):

            if key in prev_S[i: i + 2]:

                SS.append(key)

            else:

                SS.append(prev_S[i])

        cnt += 1

        t -= 1

        prev_S = SS[:]

    # print(cnt, prev_S)



print(ans)

# coding:utf-8



import sys

from collections import Counter



INF = float('inf')

MOD = 10 ** 9 + 7



def LI(): return [int(x) for x in sys.stdin.readline().split()]

def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

def II(): return int(sys.stdin.readline())

def SI(): return eval(input())





def main():

    s = SI()

    char_cnt = Counter(s)



    res = INF

    for c in list(char_cnt.keys()):

        r = s[:]

        cnt = 0

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

            t = ''

            for ss in zip(r[:-1], r[1:]):

                if c in ss:

                    t += c

                else:

                    t += ss[0]

            cnt += 1

            r = t

            # print(r)

        res = min(res, cnt)



    return res





print((main()))

# coding:utf-8
from collections import Counter


def inpl():
    return list(map(int, input().split()))


S = eval(input())
C = Counter(S)
if len(S) == 1:
    print((0))
    exit()
ans = 100
for key in list(C.keys()):
    prev_S = list(S)
    cnt = 0
    t = len(S) - 1
    while t > 0:
        if all([1 if s == key else 0 for s in prev_S]):
            ans = min(ans, cnt)
            break
        SS = []
        for i in range(t):
            if key in prev_S[i : i + 2]:
                SS.append(key)
            else:
                SS.append(prev_S[i])
        cnt += 1
        t -= 1
        prev_S = SS[:]
    # print(cnt, prev_S)
print(ans)

# coding:utf-8
import sys
from collections import Counter

INF = float("inf")
MOD = 10**9 + 7


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def LI_():
    return [int(x) - 1 for x in sys.stdin.readline().split()]


def LS():
    return sys.stdin.readline().split()


def II():
    return int(sys.stdin.readline())


def SI():
    return eval(input())


def main():
    s = SI()
    char_cnt = Counter(s)
    res = INF
    for c in list(char_cnt.keys()):
        r = s[:]
        cnt = 0
        while len(set(r)) != 1:
            t = ""
            for ss in zip(r[:-1], r[1:]):
                if c in ss:
                    t += c
                else:
                    t += ss[0]
            cnt += 1
            r = t
            # print(r)
        res = min(res, cnt)
    return res


print((main()))

+import sys - -def inpl(): -    return list(map(int, input().split())) +INF = float("inf") +MOD = 10**9 + 7 -S = eval(input()) -C = Counter(S) -if len(S) == 1: -    print((0)) -    exit() -ans = 100 -for key in list(C.keys()): -    prev_S = list(S) -    cnt = 0 -    t = len(S) - 1 -    while t > 0: -        if all([1 if s == key else 0 for s in prev_S]): -            ans = min(ans, cnt) -            break -        SS = [] -        for i in range(t): -            if key in prev_S[i : i + 2]: -                SS.append(key) -            else: -                SS.append(prev_S[i]) -        cnt += 1 -        t -= 1 -        prev_S = SS[:] -    # print(cnt, prev_S) -print(ans) +def LI(): +    return [int(x) for x in sys.stdin.readline().split()] + + +def LI_(): +    return [int(x) - 1 for x in sys.stdin.readline().split()] + + +def LS(): +    return sys.stdin.readline().split() + + +def II(): +    return int(sys.stdin.readline()) + + +def SI(): +    return eval(input()) + + +def main(): +    s = SI() +    char_cnt = Counter(s) +    res = INF +    for c in list(char_cnt.keys()): +        r = s[:] +        cnt = 0 +        while len(set(r)) != 1: +            t = "" +            for ss in zip(r[:-1], r[1:]): +                if c in ss: +                    t += c +                else: +                    t += ss[0] +            cnt += 1 +            r = t +            # print(r) +        res = min(res, cnt) +    return res + + +print((main()))