"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const h = arg[1].split(" ").map(n=>parseInt(n));
    
    const state = [...Array(N)].fill(0);
    let answer  = 0;
    let action  = 0;
    
    for(let i=0; i<N; i++) {
        if(action >= h[i]) {
            action = h[i];
        } else {
            answer += h[i] - action;
            action = h[i];
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));