from collections import Counter



def solve(s):

    cs = Counter(s).most_common()

    m = len(s)

    for c in cs:

        news = list(s)

        size = len(s)

        count = 0

        while len(Counter(news[:size]).most_common()) > 1:

            for i in range(size - 1):

                if news[i] != c[0] and news[i + 1] == c[0]:

                    news[i] = c[0]

            size -= 1

            count += 1

        if count < m:

            m = count

    return m



_s = eval(input())

print((solve(_s)))

from collections import Counter



def solve(s):

    cs = Counter(s)

    m = len(s)

    for c in cs:

        news = list(s)

        size = len(s)

        count = 0

        while len(Counter(news[:size])) > 1:

            for i in range(size - 1):

                if news[i] != c[0] and news[i + 1] == c[0]:

                    news[i] = c[0]

            size -= 1

            count += 1

        if count < m:

            m = count

    return m



_s = eval(input())

print((solve(_s)))

from collections import Counter


def solve(s):
    cs = Counter(s).most_common()
    m = len(s)
    for c in cs:
        news = list(s)
        size = len(s)
        count = 0
        while len(Counter(news[:size]).most_common()) > 1:
            for i in range(size - 1):
                if news[i] != c[0] and news[i + 1] == c[0]:
                    news[i] = c[0]
            size -= 1
            count += 1
        if count < m:
            m = count
    return m


_s = eval(input())
print((solve(_s)))

from collections import Counter


def solve(s):
    cs = Counter(s)
    m = len(s)
    for c in cs:
        news = list(s)
        size = len(s)
        count = 0
        while len(Counter(news[:size])) > 1:
            for i in range(size - 1):
                if news[i] != c[0] and news[i + 1] == c[0]:
                    news[i] = c[0]
            size -= 1
            count += 1
        if count < m:
            m = count
    return m


_s = eval(input())
print((solve(_s)))

-    cs = Counter(s).most_common() +    cs = Counter(s) -        while len(Counter(news[:size]).most_common()) > 1: +        while len(Counter(news[:size])) > 1: