syouhi0 [x,y] = 0
syouhi0 (x:xs) = syouhi1 0 x xs + syouhi0 xs

syouhi1 diff consumed [x] = 0
syouhi1 diff consumed (x:xs) = if x == consumed
                                    then syouhi1 (diff+1) consumed xs
                                    else syouhi2 diff 0 x consumed xs + syouhi1 (diff+1) consumed xs

syouhi2 diff_past diff_current consumed consumed2 [] = 0
syouhi2 diff_past diff_current consumed consumed2 (x:xs) = if x == consumed || x==consumed2
                                             then syouhi2 diff_past (diff_current+1) consumed consumed2 xs
                                             else if (diff_past/=diff_current)
                                               then 1 + syouhi2 diff_past (diff_current+1) consumed consumed2 xs
                                               else syouhi2 diff_past (diff_current+1) consumed consumed2 xs



main = do
  n <- read<$>getLine :: IO Int
  s<-getLine
  print $ syouhi0 s