import Data.List (group)
import Data.Sequence (ViewL((:<)),ViewR((:>)),(<|),(|>),viewl, viewr)
import qualified Data.Sequence as Seq


solve :: Integer -> Seq.Seq Integer -> Integer -> Integer
solve len sq m
  | Seq.length sq == 1 = m
  | Seq.length sq == 2 = min m $ max l r
  | otherwise = if l < r
                  then let (l1:<r1) = viewl rr
                      in solve len ((l+l1)<|r1) $ min m (len-l)
                  else let (l1:>r1) = viewr ll
                      in solve len (l1|>(r+r1)) $ min m (len-r)
    where (l:<rr) = viewl sq
          (ll:>r) = viewr sq

main :: IO ()
main = do
  s <- getLine :: IO String
  let sq = (Seq.fromList.map (fromIntegral.length).group) s
      ls = (fromIntegral.length) s
  print $ solve ls sq ls
