const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {
 
    const lines = input.split('\n')
    const N = lines[0] - 0
    const h = lines[1].split(' ').map(Number)

    let c = h[0]

    for (let i = 0; i < N - 1; i++) {
        if (h[i] < h[i + 1]) {
            c += h[i + 1] - h[i]
        }
    }

    console.log(c)

})(input)
