import Control.Applicative
import Control.Monad
import Data.List

solve :: String -> Int
solve ss = minimum . fmap (flip go ss) . nub $ ss
  where
    ln = length ss
    go c xs
        | all (== c) xs = ln - length xs
        | otherwise     = go c (fmap f (zip xs (tail xs)))
      where
        f (a, b)
            | a == c || b == c = c
            | otherwise        = a

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