from collections import Counter

from copy import deepcopy



s = eval(input())

c = Counter(list(s))



lS = len(set(list(s)))



if lS == 1:

    print((0))

    exit()

if lS == len(s):

    print((len(s) // 2))

    exit()

else:

    maxN = len(s)

    for key in c:

        ss = list(s)

        count = 0

        # print(">", key)

        # print(ss)

        while True:

            count += 1

            new_ss = []

            for j in range(len(ss) - 1):

                if ss[j] == key or ss[j + 1] == key:

                    new_ss.append(key)

                else:

                    new_ss.append(ss[j])

            # print(new_ss)

            ss = deepcopy(new_ss)

            if len(set(new_ss)) == 1:

                break

        # print(">", key, count)

        maxN = min(maxN, count)

    print(maxN)
from string import ascii_lowercase



# a-zまで試す

s = eval(input())

maxN = len(s)

for ch in ascii_lowercase:

    ss = list(s)

    count = 0



    if len(set(s)) == 1:

        count = 0

    else:

        while True:

            count += 1

            new_ss = []

            for j in range(len(ss) - 1):

                if ss[j] == ch or ss[j + 1] == ch:

                    new_ss.append(ch)

                else:

                    new_ss.append(ss[j])

            # print(new_ss)

            ss = new_ss

            if len(set(new_ss)) == 1:

                break

    maxN = min(maxN, count)

print(maxN)
from collections import Counter
from copy import deepcopy

s = eval(input())
c = Counter(list(s))
lS = len(set(list(s)))
if lS == 1:
    print((0))
    exit()
if lS == len(s):
    print((len(s) // 2))
    exit()
else:
    maxN = len(s)
    for key in c:
        ss = list(s)
        count = 0
        # print(">", key)
        # print(ss)
        while True:
            count += 1
            new_ss = []
            for j in range(len(ss) - 1):
                if ss[j] == key or ss[j + 1] == key:
                    new_ss.append(key)
                else:
                    new_ss.append(ss[j])
            # print(new_ss)
            ss = deepcopy(new_ss)
            if len(set(new_ss)) == 1:
                break
        # print(">", key, count)
        maxN = min(maxN, count)
    print(maxN)

from string import ascii_lowercase

# a-zまで試す
s = eval(input())
maxN = len(s)
for ch in ascii_lowercase:
    ss = list(s)
    count = 0
    if len(set(s)) == 1:
        count = 0
    else:
        while True:
            count += 1
            new_ss = []
            for j in range(len(ss) - 1):
                if ss[j] == ch or ss[j + 1] == ch:
                    new_ss.append(ch)
                else:
                    new_ss.append(ss[j])
            # print(new_ss)
            ss = new_ss
            if len(set(new_ss)) == 1:
                break
    maxN = min(maxN, count)
print(maxN)

-from collections import Counter -from copy import deepcopy +from string import ascii_lowercase +# a-zまで試す -c = Counter(list(s)) -lS = len(set(list(s))) -if lS == 1: -    print((0)) -    exit() -if lS == len(s): -    print((len(s) // 2)) -    exit() -else: -    maxN = len(s) -    for key in c: -        ss = list(s) +maxN = len(s) +for ch in ascii_lowercase: +    ss = list(s) +    count = 0 +    if len(set(s)) == 1: -        # print(">", key) -        # print(ss) +    else: -                if ss[j] == key or ss[j + 1] == key: -                    new_ss.append(key) +                if ss[j] == ch or ss[j + 1] == ch: +                    new_ss.append(ch) -            ss = deepcopy(new_ss) +            ss = new_ss -        # print(">", key, count) -        maxN = min(maxN, count) -    print(maxN) +    maxN = min(maxN, count) +print(maxN)