import Data.List

main = interact $ unlines . map (show . step_aerobics) . read' . lines
 where
  read' ("0":_) = []
  read' (_:steps:xs) = words steps : read' xs

step_aerobics steps = (`div` 2) $ sum $ map (normalize . length) (groupBy sameleg steps)
 where
  normalize n = if odd n then 1 else 2
  sameleg s1 s2 = head s1 == head s2