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 (\n -> if n<3 then n else n-2) $ map length (groupBy sameleg steps)
 where sameleg s1 s2 = head s1 == head s2