import Data.Char
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

main :: IO()
main = getLine >> (print . solve =<< getIntList)

solve :: [Int] -> Int
solve = sum . (zipWith ((max 0.).flip (-)) =<< (0:))

-- IO
readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = BS.readInt . BS.dropWhile isSpace

getIntList :: IO [Int]
getIntList = unfoldr readInt <$> BS.getLine