import Data.List (unfoldr, nub)
import Control.Arrow ((&&&))

main:: IO ()
main = do
    s <- getLine
    print $ solve s

-- |
--
-- >>> solve "sevral"
-- 3
--
-- >>> solve "jackal"
-- 2
--
-- >>> solve "zzz"
-- 0
--
-- >>> solve "whbrjpjyhsrywlqjxdbrbaomnw"
-- 8
solve :: String -> Int
solve s = minimum [length $ unfoldr (next k) s | k <- ks]
  where ks = nub s

next :: Char -> String -> Maybe (String, String)
next k s
  | all (== k) s  = Nothing
  | otherwise     = Just (s, s')
  where s' = zipWith (union k) s (tail s)

union :: Char -> Char -> Char -> Char
union k c1 c2
  | c1 == k || c2 == k  = k
  | otherwise           = c1
