import Data.Char (chr,ord)
import Data.Maybe (fromJust,isJust)

trans [] _ = []
trans [_] _ = []
trans (x:y:s) c
  | y == c = y:trans (y:s) c
  | otherwise = x:trans (y:s) c

solve :: String -> Int -> Char -> Int
solve s n c =
  if s == replicate (length s) c
    then n
    else
      solve ns (n+1) c
  where ns = trans s c

main = do
  s <- getLine :: IO String
  print $ minimum $ map (solve s 0.chr) [ord 'a'..ord 'z']
