import Data.List.Split

main :: IO ()
main = do
  getLine
  hs <- map read . words<$> getLine
  print $ solve hs

solve ::  [Int] -> Int
solve [] = 0
solve xs = sum $ map (solve . map (subtract 1)) $ splitOn [0] xs
