import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



s = eval(input())

len_s = len(s)

cnt = [0] * 26

al = [chr(ord('a') + i) for i in range(26)]

ans = [''] * (len_s + 1)

ans[0] = s

for i in range(26):

    check = list(s)

    if al[i] in check:

        ans[0] = s

        while any([al[i] != a for a in check]):

            cnt[i] += 1

            for j in range(len_s - cnt[i]):

                if ans[cnt[i] - 1][j + 1] == al[i]:

                    ans[cnt[i]] += al[i]

                else:

                    ans[cnt[i]] += ans[cnt[i] - 1][j]

            check = list(ans[cnt[i]])

            ans[cnt[i] - 1] = ''

if all(cnt[i] == 0 for i in range(26)):

    print((0))

else:

    cnt = sorted(set(cnt))

    if cnt[0] == 0:

        print((cnt[1]))

    else:

        print((cnt[0]))

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



from copy import deepcopy





def moji_list(a, b):

    # アルファベット小文字 → (97, 123)

    # アルファベット大文字 → (65, 91)

    # 半角数字 → (48, 58)

    # ひらがな → (12353, 12436)

    # カタカナ → (12449, 12532+1)

    # 全角数字 → (65296, 65306)

    return [chr(i) for i in range(a, b)]





s = list(read().rstrip().decode())

ans = float('inf')

for al in moji_list(97, 123):

    cnt = 0

    check_s = deepcopy(s)

    while len(set(check_s)) > 1:

        cnt += 1

        ss = []

        for bf, af in zip(check_s, check_s[1:]):

            ss.append(af if af == al else bf)

        check_s = ss

    ans = min(ans, cnt)

print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
s = eval(input())
len_s = len(s)
cnt = [0] * 26
al = [chr(ord("a") + i) for i in range(26)]
ans = [""] * (len_s + 1)
ans[0] = s
for i in range(26):
    check = list(s)
    if al[i] in check:
        ans[0] = s
        while any([al[i] != a for a in check]):
            cnt[i] += 1
            for j in range(len_s - cnt[i]):
                if ans[cnt[i] - 1][j + 1] == al[i]:
                    ans[cnt[i]] += al[i]
                else:
                    ans[cnt[i]] += ans[cnt[i] - 1][j]
            check = list(ans[cnt[i]])
            ans[cnt[i] - 1] = ""
if all(cnt[i] == 0 for i in range(26)):
    print((0))
else:
    cnt = sorted(set(cnt))
    if cnt[0] == 0:
        print((cnt[1]))
    else:
        print((cnt[0]))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from copy import deepcopy


def moji_list(a, b):
    # アルファベット小文字 → (97, 123)
    # アルファベット大文字 → (65, 91)
    # 半角数字 → (48, 58)
    # ひらがな → (12353, 12436)
    # カタカナ → (12449, 12532+1)
    # 全角数字 → (65296, 65306)
    return [chr(i) for i in range(a, b)]


s = list(read().rstrip().decode())
ans = float("inf")
for al in moji_list(97, 123):
    cnt = 0
    check_s = deepcopy(s)
    while len(set(check_s)) > 1:
        cnt += 1
        ss = []
        for bf, af in zip(check_s, check_s[1:]):
            ss.append(af if af == al else bf)
        check_s = ss
    ans = min(ans, cnt)
print(ans)

-s = eval(input()) -len_s = len(s) -cnt = [0] * 26 -al = [chr(ord("a") + i) for i in range(26)] -ans = [""] * (len_s + 1) -ans[0] = s -for i in range(26): -    check = list(s) -    if al[i] in check: -        ans[0] = s -        while any([al[i] != a for a in check]): -            cnt[i] += 1 -            for j in range(len_s - cnt[i]): -                if ans[cnt[i] - 1][j + 1] == al[i]: -                    ans[cnt[i]] += al[i] -                else: -                    ans[cnt[i]] += ans[cnt[i] - 1][j] -            check = list(ans[cnt[i]]) -            ans[cnt[i] - 1] = "" -if all(cnt[i] == 0 for i in range(26)): -    print((0)) -else: -    cnt = sorted(set(cnt)) -    if cnt[0] == 0: -        print((cnt[1])) -    else: -        print((cnt[0])) +from copy import deepcopy + + +def moji_list(a, b): +    # アルファベット小文字 → (97, 123) +    # アルファベット大文字 → (65, 91) +    # 半角数字 → (48, 58) +    # ひらがな → (12353, 12436) +    # カタカナ → (12449, 12532+1) +    # 全角数字 → (65296, 65306) +    return [chr(i) for i in range(a, b)] + + +s = list(read().rstrip().decode()) +ans = float("inf") +for al in moji_list(97, 123): +    cnt = 0 +    check_s = deepcopy(s) +    while len(set(check_s)) > 1: +        cnt += 1 +        ss = [] +        for bf, af in zip(check_s, check_s[1:]): +            ss.append(af if af == al else bf) +        check_s = ss +    ans = min(ans, cnt) +print(ans)