import Data.List

main = do
  s <- getLine

  print $ minimum [length s - length (solve s c) | c <- s]

  where
    solve xs c = if eqAll xs then xs else solve (aux xs) c
      where
        aux (_:[]) = []
        aux (x:y:xs) = (if x == c || y == c then c else x) : aux (y:xs)

    eqAll :: Eq a => [a] -> Bool
    eqAll = (==1) . length . nub
