import Data.List
main=print.solve=<<getLine
solve s=minimum$map(f s)$map head.group.sort$s
f s c=g 0 s where
  g i s=if all(==c)s then i else g(i+1)$(zipWith h=<<tail)s
  h c1 c2=if c1==c || c2==c then c else c1