import Data.List

chunksOf :: Int -> [a] -> [[a]]
chunksOf n = takeWhile (not . null) . unfoldr (return . splitAt n)

main = do
  getLine
  ps <- map read . words <$> getLine
  print (der ps)

der = sum . map (\[x,y] -> y-x) . chunksOf 2 . map fst . filter (uncurry (==)) . zip [1..] 