Snuke can transform a string "t" of length "N" into a string "t'" of length "N - 1" by a specific rule. For each "i" (1 ≤ i ≤ N - 1), the "i"-th character of "t'" must be either the "i"-th or "(i + 1)"-th character of "t". Given a string "s" consisting of lowercase English letters, Snuke aims to apply the operation to "s" repeatedly until all characters in "s" are the same. Find the minimum number of operations needed. Constraints: 1 ≤ |s| ≤ 100, and "s" consists of lowercase English letters. Input is given as "s", and the output should be the minimum number of operations required to achieve the objective.

# Buggy version:
import copy
char = list(map(chr, range(ord('a'), ord('z')+1)))
target = list(input())
ans = float("inf")
for c in char:
  s = copy.deepcopy(target)
  tmpans = 0
  while True:
    for i in range(len(s)-1):
      if s[i] == c or s[i+1] == c:
        s[i] = c
    s.pop()
    tmpans += 1
    flag = True
    for si in s:
      if si != s[0]:
        flag = False
    if flag==True:
      break
  if ans > tmpans:
    ans = tmpans
print(ans)
     



# Fixed version:
import copy
char = list(map(chr, range(ord('a'), ord('z')+1)))
target = list(input())
ans = float("inf")
for c in char:
  s = copy.deepcopy(target)
  tmpans = 0
  while True:
    flag = True
    for si in s:
      if si != s[0]:
        flag = False
    if flag==True:
      break
    for i in range(len(s)-1):
      if s[i] == c or s[i+1] == c:
        s[i] = c
    s.pop()
    tmpans += 1
  if ans > tmpans:
    ans = tmpans
print(ans)

# Buggy version:
from collections import Counter
s = list(input())
d =  Counter(s)
key = d.keys()
ans = 0
for k in key:
    ck = 0
    i = 0
    while True:
        if s[i] == k:
            i += 1
            if i == len(s):
                break
        else:
            cnt = 0
            while s[i + cnt] != k:
                cnt += 1
                if i + cnt == len(s):
                    break
            ck = max(ck, cnt)
            i += cnt
            if i == len(s):
                break
        ans = max(ans, ck)
if ans == len(s) - 1:
    ans = len(s)//2 + len(s)%2
print(ans)


# Fixed version:
from collections import Counter
s = list(input())
d =  Counter(s)
key = d.keys()
ans = len(s)//2 + len(s)%2
for k in key:
    ck = 0
    i = 0
    while True:
        if s[i] == k:
            i += 1
            if i == len(s):
                break
        else:
            cnt = 0
            while s[i + cnt] != k:
                cnt += 1
                if i + cnt == len(s):
                    break
            ck = max(ck, cnt)
            i += cnt
            if i == len(s):
                break
    ans = min(ans, ck)
print(ans)

# Buggy version:
import string
s = input()
n = len(s)

min_cnt = float('inf')

for c in string.ascii_lowercase:
    if c not in s:
        continue
    cnt = 0
    s_ = s[:]
    while s_:
        is_same = True
        for d in s_:
            if d != c:
                is_same = False
                break
        if is_same:
            min_cnt = min(min_cnt, n - m)
        m = len(s_) - 1
        s_next = [''] * m
        for i in range(m):
            if s_[i] == c or s_[i + 1] == c:
                s_next[i] = c
            else:
                s_next[i] = s_[i]
        s_ = s_next

print(min_cnt)


# Fixed version:
import string
s = input()
n = len(s)

min_cnt = float('inf')

for c in string.ascii_lowercase:
    if c not in s:
        continue
    cnt = 0
    s_ = s[:]
    while s_:
        m = len(s_) - 1
        is_same = True
        for d in s_:
            if d != c:
                is_same = False
                break
        if is_same:
            min_cnt = min(min_cnt, n - m-1)
        s_next = [''] * m
        for i in range(m):
            if s_[i] == c or s_[i + 1] == c:
                s_next[i] = c
            else:
                s_next[i] = s_[i]
        s_ = s_next

print(min_cnt)

# Buggy version:
S = input()
ans = 10e9
voc = set(S)
for c in voc:
    cnt = 0
    tmp = list(S)

    while True:
        cnt += 1
        for u in range(len(tmp)-1):
            tmp[u] = c if tmp[u] == c or tmp[u+1] == c else tmp[u]
            
        tmp.pop()
        if all([w == c for w in tmp]):
            ans = min(cnt, ans)
            break

print(ans)

# Fixed version:
S = input()
ans = 10e9

voc = set(S)
for c in voc:
    cnt = 0
    tmp = list(S)

    while True:
        if all([w == c for w in tmp]):
            ans = min(cnt, ans)
            break
        cnt += 1
        for u in range(len(tmp)-1):
            tmp[u] = c if tmp[u] == c or tmp[u+1] == c else tmp[u]    
        tmp.pop()


print(ans)

# Buggy version:
#AGC016-A
from collections import Counter 
s = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"
cnt = 0
result = []
for i in alphabet:
    s_tmp = s 
    cnt = 0
    for k in range(len(s_tmp)):
        s_new= ""
        for j in range(len(s_tmp)-1):
            if s_tmp[j] == i or s_tmp[j+1] == i:
                s_new += i
            else:
                s_new += s_tmp[j]
        cnt += 1
        s_tmp = s_new
        if len(set(s_new)) == 1:
            result.append(cnt)
            break
            
 

#print(result)
print(min(result))



# Fixed version:
#AGC016-A
from collections import Counter 
s = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"

result = []
if len(set(s)) == 1:
    result.append(0)
for i in alphabet:
    s_tmp = s 
    cnt = 0
    for k in range(len(s_tmp)):
        s_new= ""
        for j in range(len(s_tmp)-1):
            if s_tmp[j] == i or s_tmp[j+1] == i:
                s_new += i
            else:
                s_new += s_tmp[j]
        cnt += 1
        if len(set(s_new)) == 1:
            result.append(cnt)
            break        

        s_tmp = s_new
        
            
 

#print(result)
print(min(result))

# Buggy version:
from collections import Counter

A = list(input())


S = A
MIN = 100
for t in set(S):
    count = 0
    while True:
        T = [None] * (len(S)-1)
        for i in range(len(T)):
            if S[i] == t or S[i+1] == t:
                T[i] = t
            else:
                T[i] = S[i]

        S = T
        count += 1
        if len(set(S)) == 1:
            break

    MIN = min(count,MIN)
    S = A

print(MIN)


# Fixed version:
from collections import Counter

A = list(input())
S = A
MIN = 2000
for t in set(A):
    count = 0
    S = A
    while count <= MIN:
        if len(set(S)) == 1:
            MIN = min(count,MIN)
            break
        T = [None] * (len(S)-1)
        for i in range(len(T)):
            if S[i] == t or S[i+1] == t:
                T[i] = t
            else:
                T[i] = S[i]

        S = T
        count += 1


print(MIN)

# Buggy version:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
s=list(input())
n=len(s)
s_set=set(s)
c=Counter(s)
dic=[]
for i in s_set:
    bef=-1
    delta=0
    if c[i]==1:
        continue
    else:
        print(i)
        for j in range(n):
            if  i==s[j]:
                res=j-bef-1
                bef=j
                delta = max(delta,res)
        res=n-1-bef
        print(bef)
        dic.append(max(delta,res))
print(dic)
if not dic:
  print(n//2)
else:
  print(min(n//2,min(dic)))


# Fixed version:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
s=list(input())
n=len(s)
s_set=set(s)
c=Counter(s)
dic=[]
for i in s_set:
    bef=-1
    delta=0
    if c[i]==1:
        continue
    else:
        for j in range(n):
            if  i==s[j]:
                res=j-bef-1
                bef=j
                delta = max(delta,res)
        res=n-1-bef
        dic.append(max(delta,res))
if not dic:
  print(n//2)
else:
  print(min(n//2,min(dic)))

# Buggy version:
S=input()
A="abcdefghijklmnopqrstuvwxyz"
minimum=len(S)//2
for a in set(S):
    maximum=0
    ans_max=0
    p=0
    for s in S:
        if a==s:
            ans_max=max(p-1,maximum)
            p=0
        else:
            p+=1
    minimum=min(ans_max,minimum)
print(minimum)

# Fixed version:
S=input()
A="abcdefghijklmnopqrstuvwxyz"
minimum=len(S)//2
for a in A:
    ans_max=0
    p=0
    for s in S:
        if a==s:
            ans_max=max(p,ans_max)
            p=0
        else:
            p+=1
    ans_max=max(p,ans_max)
    minimum=min(ans_max,minimum)
print(minimum)

# Buggy version:
S = list(input())
res = len(S)
kind_all = set(S)
for i in kind_all:
    temp = S.split(i)
    cnt = 0
    for j in temp:
        cnt = max(cnt,len(j))
    res = min(res,cnt)
print(res)

# Fixed version:
S = input()
res = len(S)
kind_all = set(S)
for i in kind_all:
    temp = S.split(i)
    cnt = 0
    for j in temp:
        cnt = max(cnt,len(j))
    res = min(res,cnt)
print(res)

# Buggy version:
S = input()
uni_s = list(set(list(S)))

ans = len(S) - 1

# -1,1
for s in uni_s:
  L = len(S)
  T = list(S)
  all_same = [s == t for t in S]
  cnt = 0
  while not all(all_same):
    newT = [False] * (L-1)
    for i in range(L):
      t = T[i]
      if s == t:
        if i < L-1:
          newT[i] = t
        if 0 <= i-1:
          newT[i-1] = t
      else:
        if i < L-1 and not newT[i]:
          newT[i] = t
        if 0 <= i-1 and not newT[i-1]:
          newT[i-1] = t
    
    all_same = [s==t for t in newT]
    T = newT
    L = len(T)
  ans = min(ans,cnt)

print(ans)
      
    


# Fixed version:
S = input()
uni_s = list(set(list(S)))

ans = len(S) - 1

# -1,1
for s in uni_s:
  L = len(S)
  T = list(S)
  all_same = [s == t for t in S]
  cnt = 0
  while not all(all_same):
    cnt += 1
    newT = [False] * (L-1)
    for i in range(L):
      t = T[i]
      if s == t:
        if i < L-1:
          newT[i] = t
        if 0 <= i-1:
          newT[i-1] = t
      else:
        if i < L-1 and not newT[i]:
          newT[i] = t
        if 0 <= i-1 and not newT[i-1]:
          newT[i-1] = t
    
    all_same = [s==t for t in newT]
    T = newT
    L = len(T)
  ans = min(ans,cnt)

print(ans)

# Buggy version:
s=input()
ans=1000
for i in range(26):
  if chr(97+i) not in s:continue
  S=s
  cnt=0
  while(len(set(S)))!=1:
    cnt+=1
    t=""
    for j in range(len(S)-1):
      if S[j] == chr(97+i) or S[j+1] == chr(97+i):
        t+=chr(97+i)
      else:
        t+=S[j]
  ans=min(cnt,ans)
print(ans)

# Fixed version:
s=input()
ans=1000
for i in range(26):
  if chr(97+i) not in s:continue
  S=s
  cnt=0
  while(len(set(S)))!=1:
    cnt+=1
    t=""
    for j in range(len(S)-1):
      if S[j] == chr(97+i) or S[j+1] == chr(97+i):
        t+=chr(97+i)
      else:
        t+=S[j]
    S=t
  ans=min(cnt,ans)
print(ans)

# Buggy version:
s = input()
l = list(set(s))

min_c = 10**8
for i in l:
    old_s = s
    new_s = ''
    idx = 1
    c = 0
    while True:
        for j in range(len(s)-idx):
            if old_s[j] == i or old_s[j+1] == i:
                new_s += i
            
            else:
                new_s += old_s[j]
        
        idx += 1
        c += 1
        
        if len(set(new_s)) == 1:
            break
        
        else:
           old_s = new_s
           new_s = ''
    
    min_c = min(min_c,c)

print(min_c)
    

# Fixed version:
s = input()
l = list(set(s))

if len(set(s)) == 1:
    print(0)
    exit()

min_c = 10**8
for i in l:
    old_s = s
    new_s = ''
    idx = 1
    c = 0
    
    while True:
        for j in range(len(s)-idx):
            if old_s[j] == i or old_s[j+1] == i:
                new_s += i
            
            else:
                new_s += old_s[j]
        
        idx += 1
        c += 1
        
        if len(set(new_s)) == 1:
            break
        
        else:
           old_s = new_s
           new_s = ''
    
    min_c = min(min_c,c)

print(min_c)

# Buggy version:
s = input()
al = set(list(s))    
ans = 100

for c in al:
    L = list(s.split(c))
    print(L)
    tmp = 0
    for st in L:
        tmp = max(tmp, len(st))
    #tmp = max(tmp, len(L[0]))
    #tmp = max(tmp, len(L[-1]))
    ans = min(tmp, ans)
    #print(ans)
print(ans)

# Fixed version:
s = input()
al = set(list(s))
ans = 100
for c in al:
    L = list(s.split(c))
    tmp = 0
    for st in L:
        tmp = max(tmp,len(st))
    tmp = max(tmp,len(L[0]))
    tmp = max(tmp,len(L[-1]))
    ans = min(tmp,ans)
print(ans)

# Buggy version:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = 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:
    s = list(set(s))
    s.sort()
    if s[0] == 0:
        print(s[1])
    else:
        print(s[0])


# Fixed version:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = 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])

# Buggy version:
s=input()
n=len(s)
ans=n
for i in range(97, 97+26):
    x=chr(i)
    cnt=s.count(x)
    if cnt!=0:
        t=list(s)
        for j in range(n-1):
            u=[""]*(n-1-j)
            for k in range(n-1-j):
                if t[k]==x or t[k+1]==x:
                    u[k]=x
                else:
                    u[k]=t[k]
            if u.count(x)==n-1-j:
                ans=min(ans,j+1)
                break
            else:
                t=u
print(ans)

# Fixed version:
s=input()
n=len(s)
ans=n
for i in range(97, 97+26):
    x=chr(i)
    cnt=s.count(x)
    if cnt==n:
        ans=0
        break
    if cnt!=0:
        t=list(s)
        for j in range(n-1):
            u=[""]*(n-1-j)
            for k in range(n-1-j):
                if t[k]==x or t[k+1]==x:
                    u[k]=x
                else:
                    u[k]=t[k]
            if u.count(x)==n-1-j:
                ans=min(ans,j+1)
                break
            else:
                t=u
print(ans)

# Buggy version:
from sys import stdin
import string

t = stdin.readline().rstrip()
alpha = string.ascii_lowercase
mi = 10**10

for target in alpha:
    s = t
    cnt = 0
    while True:
        cnt += 1
        sin = ""
        for i in range(len(s)-1):
            sin += s[i] if s[i] == target else s[i+1]
        s = sin
        if s.count(target) == len(s):
            break
    mi = min(mi,cnt)

print(mi)

# Fixed version:
from sys import stdin
import string

t = stdin.readline().rstrip()
alpha = string.ascii_lowercase
mi = 10**10
if len(set(t)) == 1:
    print(0)
    exit() 
for target in alpha:
    s = t
    cnt = 0
    while True:
        cnt += 1
        sin = ""
        for i in range(len(s)-1):
            sin += s[i] if s[i] == target else s[i+1]
        s = sin
        if s.count(target) == len(s):
            break
    mi = min(mi,cnt)

print(mi)

# Buggy version:
s = input()
ans = float("inf")
for i in range(26):
  c = chr(ord("a")+i)
  if c not in s:
    continue
  temp = s
  count = 0
  while set(temp) != {c}:
    t = ""
    for j in range(len(temp)-1):
      if temp[j] == c or temp[j+1] == c:
        t += c
      else:
        t += "#"
    temp = t
    count += 1
    print(temp)
  ans = min(ans, count)
print(ans)

# Fixed version:
s = input()
ans = float("inf")
for i in range(26):
  c = chr(ord("a")+i)
  if c not in s:
    continue
  temp = s
  count = 0
  while set(temp) != {c}:
    t = ""
    for j in range(len(temp)-1):
      if temp[j] == c or temp[j+1] == c:
        t += c
      else:
        t += "#"
    temp = t
    count += 1
  ans = min(ans, count)
print(ans)

# Buggy version:
s = input().strip()
n = len(s)
D = {chr(i):[] for i in range(97,123)}
for i in range(97,123):
    for j in range(n):
        if s[j]==chr(i):
            D[chr(i)].append(j)
cntmin = 1000
for i in range(97,123):
    if len(D[chr(i)])==1:
        d = D[chr(i)][0]
        cnt = max(d,n-d)
        cntmin = min(cntmin,cnt)
    elif len(D[chr(i)])>1:
        A = []
        for j in range(len(D[chr(i)])):
            if j==0:
                A.append(D[chr(i)][0])
                A.append(D[chr(i)][1]-D[chr(i)][0]-1)
            elif j==len(D[chr(i)])-1:
                A.append(n-D[chr(i)][-1])
            else:
                A.append(D[chr(i)][j+1]-D[chr(i)][j]-1)
        cntmin = min(cntmin,max(A))
print(cntmin)

# Fixed version:
s = input().strip()
n = len(s)
D = {chr(i):[] for i in range(97,123)}
for i in range(97,123):
    for j in range(n):
        if s[j]==chr(i):
            D[chr(i)].append(j)
cntmin = 1000
for i in range(97,123):
    if len(D[chr(i)])==1:
        d = D[chr(i)][0]
        cntmin = min(cntmin,max(d,n-1-d))
    elif len(D[chr(i)])>1:
        A = []
        for j in range(len(D[chr(i)])):
            if j==0:
                A.append(D[chr(i)][0])
            if j<len(D[chr(i)])-1:
                A.append(D[chr(i)][j+1]-D[chr(i)][j]-1)
        A.append(n-1-D[chr(i)][-1])
        cntmin = min(cntmin,max(A))
print(cntmin)

# Buggy version:
s = list(input())
N = len(s)
if N == 1:
    print (0)
    exit()

    ans = 99
for i in range(1, N): #残す文字数
    tmp = 0 #残す文字以外の最大連続数
    count = 0 #残す文字以外が何文字続いているかをカウント
    for j in range(i):
        if s[j] == s[i]:
            tmp = max(tmp, count)
            count = 0
        else:
            count += 1
    tmp = max(tmp, count)
    ans = min(ans, max(tmp, N - i - 1))

print (ans)

# Fixed version:
s = list(input())
N = len(s)
if N == 1:
    print (0)
    exit()

ans = 99
for i in range(1, N): #残す文字数
    tmp = 0 #残す文字以外の最大連続数
    count = 0 #残す文字以外が何文字続いているかをカウント
    for j in range(i):
        if s[j] == s[i]:
            tmp = max(tmp, count)
            count = 0
        else:
            count += 1
    tmp = max(tmp, count)
    ans = min(ans, max(tmp, N - i - 1))

print (ans)

# Buggy version:
s=input()
l=len(s)
a=[1]*(l+1)
c=[]
x=0
while(x<=l-1):
  if(a[x]==1):
    a[x]=0
    k=0
    b=[x-1]
    t=s+s[x]
    for i in range(x+1,l+1):
      if(t[x]==t[i]):
        b.append(k)
        a[i]=0
        k=0
      else:
        k+=1
    c.append(max(b))
  x+=1
print(min(c))

# Fixed version:
s=input()
l=len(s)
a=[1]*(l+1)
c=[]
x=0
while(x<=l-1):
  if(a[x]==1):
    a[x]=0
    k=0
    b=[x]
    t=s+s[x]
    for i in range(x+1,l+1):
      if(t[x]==t[i]):
        b.append(k)
        a[i]=0
        k=0
      else:
        k+=1
    c.append(max(b))
  x+=1
print(min(c))

# Buggy version:
from sys import stdin

# n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# data = [stdin.readline().rstrip().split() for _ in range(n)]

ans = len(s)
for c in range(ord('a'), ord('z')+1):
    cnt, cntMax = 0, 0
    for i in range(0, len(s)-1):
        if s[i] == chr(c):
            cntMax = max(cnt, cntMax)
            cnt = 0
            continue
        cnt += 1
    cntMax = max(cnt, cntMax)
    ans = min(ans, cntMax)
print(ans, '\n')
# print(*data, sep='\n')


# Fixed version:
from sys import stdin

# n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# data = [stdin.readline().rstrip().split() for _ in range(n)]

ans = len(s)
for c in range(ord('a'), ord('z')+1):
    cnt, cntMax = 0, 0
    for i in range(0, len(s)):
        if s[i] == chr(c):
            cntMax = max(cnt, cntMax)
            cnt = 0
            continue
        cnt += 1
    cntMax = max(cnt, cntMax)
    ans = min(ans, cntMax)
print(ans, '\n')
# print(*data, sep='\n')

# Buggy version:
s = input()
l = set(list(s))
N = len(s)
n = len(s)
ans = 0

for ll in l:
    S = s
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)


# Fixed version:
s = input()
l = list(s)
N = len(s)
n = len(s)
ans = 0

if len(set(s)) == 1:
    print(0)
    exit()

for ll in l:
    S = s
    n = N
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)

# Buggy version:

s=input()
def change(s,x):
    t=s
    u=''
    for i in range(1,len(s)):
        for j in range(len(t)-1):
            if t[j]==x or t[j+1]==x:
                u+=x
            else:
                u+=t[j]
        if u.count(x)==len(u):
            return i
        t=u
        u=''
m=[]
for i in s:
    m.append(change(s,i))
print(min(m))

# Fixed version:

s=input()
def change(s,x):
    if s.count(x)==len(s):
        return 0
    t=s
    u=''
    for i in range(1,len(s)):
        for j in range(len(t)-1):
            if t[j]==x or t[j+1]==x:
                u+=x
            else:
                u+=t[j]
        if u.count(x)==len(u):
            return i
        t=u
        u=''
m=[]
for i in s:
    m.append(change(s,i))
print(min(m))

# Buggy version:
check='abcdefghijklmnopqrstuvwxyz'
s=input()
l=len(s)
pos=[0]*26
for i in range(l):
  for j in range(26):
    if s[i]==check[j]:
      pos[j].append(i)
ans=10**9:
  for i in range(26):
    tmp=0
    for j in range(len(pos[i])-1):
      tmp=max(tmp,pos[i][j+1]-pos[i][j])
    tmp=max(tmp,(l-1)-pos[i][-1])
    ans=min(ans,tmp)
print(ans)

# Fixed version:
check='abcdefghijklmnopqrstuvwxyz'
s=input()
l=len(s)
pos=[[0] for _ in range(26)]
for i in range(l):
  for j in range(26):
    if s[i]==check[j]:
      pos[j].append(i+1)
ans=10**9
for i in range(26):
  tmp=0
  for j in range(len(pos[i])-1):
    tmp=max(tmp,pos[i][j+1]-pos[i][j]-1)
  tmp=max(tmp,l-pos[i][-1])
  ans=min(ans,tmp)
print(ans)

# Buggy version:
from collections import Counter
ss = input()

ans = 1000
candidates = list(set(ss))
for s in candidates:
    count = 0
    t = list(ss)
    while True:
        t = [t[i] if t[i+1] != s else t[i+1] for i in range(len(t)-1)]
        count += 1
        # print(count, s, t)
        if len(set(t))==1:
            ans = min(ans, count)
            break
print(ans)

# Fixed version:
from collections import Counter
ss = input()

ans = 1000
candidates = set(ss)
for s in candidates:
    count = 0
    t = list(ss)
    while True:
        if len(set(t))==1:
            ans = min(ans, count)
            break
        t = [t[i] if t[i+1] != s else t[i+1] for i in range(len(t)-1)]
        count += 1
print(ans)

# Buggy version:
s=list(input())
p=[chr(ord("a")+i)for i in range(26)]
q=100
for i in range(26):
    t=p[i]
    d=s[:]
    c=0
    while len(d)>0:
        c+=1
        for j in range(len(d)-1):
            if d[j]==t or d[j+1]==t:
                d[j]=t
        else:
            d.pop(-1)
            if len(list(set(d)))==1 and d[0]==t:
                break
    q=min(q,c)
print(q)

# Fixed version:
s=list(input())
p=[chr(ord("a")+i)for i in range(26)]
q=100
if len(list(set(s)))==1:
    print(0)
else:
    for i in range(26):
        t=p[i]
        d=s[:]
        c=0
        while len(d)>0:
            c+=1
            for j in range(len(d)-1):
                if d[j]==t or d[j+1]==t:
                    d[j]=t
            else:
                d.pop(-1)
                if len(list(set(d)))==1 and d[0]==t:
                    break
        q=min(q,c)
    print(q)

# Buggy version:
# coding:utf-8

from collections import Counter


def inpl(): return list(map(int, input().split()))


S = input()
C = Counter(S)
if len(S) == 1:
    print(0)
    exit()

ans = 100
for key in C.keys():
    prev_S = list(S)
    cnt = 0
    t = len(S) - 1
    while t > 0:
        if all([1 if s == key else 0 for s in prev_S]):
            ans = min(ans, cnt)
            break
        SS = []
        for i in range(t):
            if key in prev_S[i: i + 2]:
                SS.append(key)
            else:
                SS.append(prev_S[i])
        cnt += 1
        t -= 1
        prev_S = SS[:]
    print(cnt, prev_S)

print(ans)


# Fixed version:
# coding:utf-8

from collections import Counter


def inpl(): return list(map(int, input().split()))


S = input()
C = Counter(S)
if len(S) == 1:
    print(0)
    exit()

ans = 100
for key in C.keys():
    prev_S = list(S)
    cnt = 0
    t = len(S) - 1
    while t > 0:
        if all([1 if s == key else 0 for s in prev_S]):
            ans = min(ans, cnt)
            break
        SS = []
        for i in range(t):
            if key in prev_S[i: i + 2]:
                SS.append(key)
            else:
                SS.append(prev_S[i])
        cnt += 1
        t -= 1
        prev_S = SS[:]
    # print(cnt, prev_S)

print(ans)

# Buggy version:
def itoa(i):
    alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
                'p','q','r','s','t','u','v','w','x','y','z']
    return alphabet[i]
s = input()
score_list = []
for i in range(26):
    c = itoa(i)
    prev = 0
    score = 0
    flag=False
    for j in range(len(s)):
        if c==s[j]:
            score=max(j-prev-1,score)
            flag=True
            prev=j
    score = max(j-prev,score)
    if flag==False:
        score=10**3
    score_list.append(score)
    
print(min(score_list))

# Fixed version:
def itoa(i):
    alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
                'p','q','r','s','t','u','v','w','x','y','z']
    return alphabet[i]
s = input()
score_list = []
for i in range(26):
    c = itoa(i)
    prev = -1
    score = 0
    flag=False
    for j in range(len(s)):
        if c==s[j]:
            score=max(j-prev-1,score)
            flag=True
            prev=j
    score = max(j-prev,score)
    if flag==False:
        score=10**3
    score_list.append(score)

print(min(score_list))

# Buggy version:
S = input()
ans = min(max(map(len, S.split(c)))
          for c in [chr(i + 97) for i in range(26)]
          if c not in S))
print(ans)

# Fixed version:
S = input()
ans = min(max(map(len, S.split(c)))
          for c in [chr(i + 97) for i in range(26)]
          if c in S)
print(ans)

# Buggy version:
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def main() -> None:
    s = next_str()
    dic = [set() for _ in range(len(s))]

    flg = False

    for i in range(len(s)):
        dic[i].add(s[i])

    print(dic)

    while True:
        for c in range(ord('a'), ord('z') + 1):
            for i in range(len(dic)):
                if chr(c) not in dic[i]:
                    break
            else:
                flg = True

        for i in range(len(dic) - 1):
            dic[i] |= dic[i + 1]

        if flg: break
        dic = dic[:-1]

    print(len(s) - len(dic))


if __name__ == '__main__':
    main()

# Fixed version:
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def main() -> None:
    s = next_str()
    dic = [set() for _ in range(len(s))]

    flg = False

    for i in range(len(s)):
        dic[i].add(s[i])

    while True:
        for c in range(ord('a'), ord('z') + 1):
            for i in range(len(dic)):
                if chr(c) not in dic[i]:
                    break
            else:
                flg = True

        for i in range(len(dic) - 1):
            dic[i] |= dic[i + 1]

        if flg: break
        dic = dic[:-1]

    print(len(s) - len(dic))


if __name__ == '__main__':
    main()

# Buggy version:
S = input()
P = list(set(P))
ANS = []
for i in range(len(P)) :
    T = list(S.split(P[i]))
    U = []
    for j in range(len(T)) :
        U.append(len(T[j]))
    ANS.append(max(U))
print(min(ANS))


# Fixed version:
S = input()
P = list(set(S))
ANS = []
for i in range(len(P)) :
    T = list(S.split(P[i]))
    U = []
    for j in range(len(T)) :
        U.append(len(T[j]))
    ANS.append(max(U))
print(min(ANS))

# Buggy version:
#s = input()
s = "zzz"
s = "whbrjpjyhsrywlqjxdbrbaomnw"
f = {}
g = {}

chars = [c for c in s]
#print(chars)

for char in chars:
    f[char] = []
    f[char].append(-1)
    for i, c in enumerate(s):
        if(c==char):
            f[char].append(i)
    f[char].append(len(s))

max_len_all = len(s)
for char in chars:
    max_len = 0
    for i in range(len(f[char])-1):
        max_len = max(max_len, f[char][i+1]-f[char][i])
    g[char] = max_len
    if(g[char]<max_len_all):
        ans = char
        max_len_all = g[char]



#print(f)
#print(g)
print(max_len_all-1)


# Fixed version:
s = input()
f = {}
g = {}

chars = [c for c in s]
#print(chars)

for char in chars:
    f[char] = []
    f[char].append(-1)
    for i, c in enumerate(s):
        if(c==char):
            f[char].append(i)
    f[char].append(len(s))

max_len_all = len(s)
for char in chars:
    max_len = 0
    for i in range(len(f[char])-1):
        max_len = max(max_len, f[char][i+1]-f[char][i])
    g[char] = max_len
    if(g[char]<max_len_all):
        ans = char
        max_len_all = g[char]



#print(f)
#print(g)
print(max_len_all-1)

# Buggy version:
def main():
    s = input()
    c_set = set(s)

    min_c = len(s)
    for i in range(len(s)):
        if s[i] in c_set:
            max_c, f_idx = i, i
            for j in range(i+1, len(s)):
                if s[i] == s[j] or j == len(s) - 1:
                    if max_c < j - f_idx - 1:
                        max_c = j - f_idx - 1

                    f_idx = j

            if max_c < min_c:
                min_c = max_c

            c_set.remove(s[i])

    print(min_c)


if __name__ == '__main__':
    main()


# Fixed version:
def main():
    s = input()
    c_set = set(s)

    min_c = len(s)
    for i in range(len(s)):
        if s[i] in c_set:
            max_c, f_idx = i, i
            for j in range(i+1, len(s)):
                if s[i] == s[j]:
                    if max_c < j - f_idx - 1:
                        max_c = j - f_idx - 1
                    f_idx = j

                elif j == len(s) - 1:
                    if max_c < j - f_idx:
                        max_c = j - f_idx

            if max_c < min_c:
                min_c = max_c

            c_set.remove(s[i])

    print(min_c)


if __name__ == '__main__':
    main()

# Buggy version:
S = input()
chars = set(S)
ans = len(S)

for c in chas :
    m = max(len(_) for _ in S.split(c))
    ans = min(ans, m)

print(ans)

# Fixed version:
S = input()
chars = set(S)
ans = len(S)

for c in chars :
    m = max(len(_) for _ in S.split(c))
    ans = min(ans, m)

print(ans)

# Buggy version:
s=input()
#s="whbrjpjyhsrywlqjxdbrbaomnw"
minCost=len(s)
for char in char_set:
    m=max([len(_) for _ in s.split(char)])
    if m<minCost:
        minCost=m
print(minCost)

# Fixed version:
s=input()
#s="whbrjpjyhsrywlqjxdbrbaomnw"
minCost=len(s)
char_set=set(s)
for char in char_set:
    m=max([len(_) for _ in s.split(char)])
    if m<minCost:
        minCost=m
print(minCost)

# Buggy version:

a = input()

for target in set(s):
    s = a
    j = 0
    min = 10000
    while(1):
        
        if len(set(s)) == 1:
            break
        new_s = ""
        for i in range(len(s)-1):
            if s[i] == target or s[i+1] == target:
                new_s +=target
            else:
                new_s += s[i]
        j+=1;
        s = new_s
    if min > j:
        min = j
print(min)

# Fixed version:
a = input()
min = 10000
for target in set(a):
    s = a
    j = 0
    while(1):
        
        if len(set(s)) == 1:
            break
        new_s = ""
        for i in range(len(s)-1):
            if s[i] == target or s[i+1] == target:
                new_s +=target
            else:
                new_s += s[i]
        j+=1;
        if j > min:
            break
        s = new_s
    if min > j:
        min = j

print(min)

# Buggy version:
ans = 999
s = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
for i in range(26):
    ls = [s]
    j = 0
    while True:
        ls.append([])
        for k in range(len(ls[j])-1):
            if ls[j][k] == abc[i] or ls[j][k+1] == abc[i]:
                ls[j+1].append(abc[i])
            else:
                ls[j+1].append(ls[j][k])
        j += 1
        if ls[j] == list(abc[i]*(len(s)-j)):
            break
        
    ans = min(ans, len(ls)-1) 
        
print(ans)

# Fixed version:
ans = 999
s = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
for i in range(26):
    ls = [list(s)]
    j = 0
    while True:
        if ls[j] == list(abc[i]*(len(s)-j)):
            break
        ls.append([])
        for k in range(len(ls[j])-1):
            if ls[j][k] == abc[i] or ls[j][k+1] == abc[i]:
                ls[j+1].append(abc[i])
            else:
                ls[j+1].append(ls[j][k])
        j += 1
        
        
    ans = min(ans, len(ls)-1) 
        
print(ans)

# Buggy version:
s = input()
n = len(s)
min_t = float('inf')
for i in range(n):
    target = s[i]
    pre = 0
    max_t = 0
    for j in range(n):
        if s[j] == s[i]:
            max_t = max(max_t, j-pre-1)
            pre = j
    max_t = max(max_t, n - pre-1)
    if max_t < min_t:
        min_t = min(min_t, max_t)
print(min_t)

# Fixed version:
s = input()
n = len(s)
min_t = float('inf')
for i in range(n):
    target = s[i]
    pre = -1
    max_t = 0
    for j in range(n):
        if s[j] == s[i]:
            max_t = max(max_t, j-pre-1)
            pre = j
    max_t = max(max_t, n - pre-1)
    if max_t < min_t:
        min_t = min(min_t, max_t)
print(min_t)