import Control.Monad
import Data.List
import qualified Data.Map.Strict as M

main=do
    s<-getLine
    print $ sol (length s) s

sol n s
    | length iss == 1 = 0
    | otherwise = minimum $ map (\is->maximum $ unfoldr cf (n,is)) iss
    where
        iss = M.elems $ foldl' (\m (c,i)->M.alter (altf i) c m) M.empty $ zip s [0..]

altf i (Just u) = Just (i:u)
altf i Nothing = Just [i]

cf (-1, _) = Nothing
cf (p, []) = Just(p, (-1,[]))
cf (p, i:is) = Just(p-i-1, (i,is))