"use strict";
function Main(input) {
    let lines = input.split("\n");
    let N = lines.shift() - 0;
    let h = lines.shift().split(/\s/).map((v) => v - 0);
    let ans = 0;
    let act = 0;
    for (let n = 0; n < N; n++) {
        if (act >= h[n]) act = h[n];
        else {
            ans += h[n] - act;
            act = h[n];
        }
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
