import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main = getLine >> readLine >>= print . solve 

solve :: [Int] -> Int
solve = count 0 . zip [1..]
    where
        count acc ((i, x) : (j, y) : zs)
            | i == x && j == y = count (acc + 1) zs
            | i == x = count (acc + 1) zs
            | otherwise = count acc $ (j, y) : zs
        count acc ((i, x) : _)
            | i == x = acc + 1
            | otherwise = acc
        count acc _ = acc

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine