import sys

input=sys.stdin.readline

import collections



def main():

    S = input().strip()

    mi = len(S)

    for c in list(collections.Counter(S).keys()):

        s = list(S)

        n = 0

        while len(list(collections.Counter(s).keys())) > 1:

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

                if s[i+1] == c:

                    s[i] = c

            s.pop()

            n += 1

        mi = min(mi, n)

    print(mi)



if __name__ == '__main__':

    main()

import sys

input=sys.stdin.readline



def main():

    S = input().strip()

    mi = len(S)

    for c in set(S):

        s = list(S)

        n = 0

        while len(set(s)) > 1:

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

                if s[i+1] == c:

                    s[i] = c

            s.pop()

            n += 1

        mi = min(mi, n)

    print(mi)



if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline
import collections


def main():
    S = input().strip()
    mi = len(S)
    for c in list(collections.Counter(S).keys()):
        s = list(S)
        n = 0
        while len(list(collections.Counter(s).keys())) > 1:
            for i in range(len(s) - 1):
                if s[i + 1] == c:
                    s[i] = c
            s.pop()
            n += 1
        mi = min(mi, n)
    print(mi)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline


def main():
    S = input().strip()
    mi = len(S)
    for c in set(S):
        s = list(S)
        n = 0
        while len(set(s)) > 1:
            for i in range(len(s) - 1):
                if s[i + 1] == c:
                    s[i] = c
            s.pop()
            n += 1
        mi = min(mi, n)
    print(mi)


if __name__ == "__main__":
    main()

-import collections -    for c in list(collections.Counter(S).keys()): +    for c in set(S): -        while len(list(collections.Counter(s).keys())) > 1: +        while len(set(s)) > 1: