import collections

s = eval(input())

ls = len(s)

c = collections.Counter(s)

mi = ls

valuePlaces = []

for v,k in list(c.items()):

    co = 0

    valuePlaces.clear()

    for i in range(ls):

        if s[i] == v:

            valuePlaces.append(i)

    ushiro = ls-valuePlaces[-1]-1

    #print(ushiro,v)

    maxLen = 0

    len_vp = len(valuePlaces)

    #print(len_vp)

    for i in range(len_vp):

        start = valuePlaces[i]

        if i == 0:

            goal = -1

        else:

            goal = valuePlaces[i-1]

        maxLen = max(start-goal-1,maxLen)

    mi = min (mi,max(maxLen,ushiro))

print(mi)







import collections

s = eval(input())

ls = len(s)

c = set(s)

mi = ls

valuePlaces = []

for v in c:

    co = 0

    valuePlaces.clear()

    for i in range(ls):

        if s[i] == v:

            valuePlaces.append(i)

    ushiro = ls-valuePlaces[-1]-1

    maxLen = 0

    len_vp = len(valuePlaces)

    for i in range(len_vp):

        start = valuePlaces[i]

        if i == 0:

            goal = -1

        else:

            goal = valuePlaces[i-1]

        maxLen = max(start-goal-1,maxLen)

    mi = min (mi,max(maxLen,ushiro))

print(mi)
import collections

s = eval(input())
ls = len(s)
c = collections.Counter(s)
mi = ls
valuePlaces = []
for v, k in list(c.items()):
    co = 0
    valuePlaces.clear()
    for i in range(ls):
        if s[i] == v:
            valuePlaces.append(i)
    ushiro = ls - valuePlaces[-1] - 1
    # print(ushiro,v)
    maxLen = 0
    len_vp = len(valuePlaces)
    # print(len_vp)
    for i in range(len_vp):
        start = valuePlaces[i]
        if i == 0:
            goal = -1
        else:
            goal = valuePlaces[i - 1]
        maxLen = max(start - goal - 1, maxLen)
    mi = min(mi, max(maxLen, ushiro))
print(mi)

import collections

s = eval(input())
ls = len(s)
c = set(s)
mi = ls
valuePlaces = []
for v in c:
    co = 0
    valuePlaces.clear()
    for i in range(ls):
        if s[i] == v:
            valuePlaces.append(i)
    ushiro = ls - valuePlaces[-1] - 1
    maxLen = 0
    len_vp = len(valuePlaces)
    for i in range(len_vp):
        start = valuePlaces[i]
        if i == 0:
            goal = -1
        else:
            goal = valuePlaces[i - 1]
        maxLen = max(start - goal - 1, maxLen)
    mi = min(mi, max(maxLen, ushiro))
print(mi)

-c = collections.Counter(s) +c = set(s) -for v, k in list(c.items()): +for v in c: -    # print(ushiro,v) -    # print(len_vp)