const input = require("fs").readFileSync("/dev/stdin", "utf8");
var N, H
input.split('\n').map((x, i) => i === 1 ? x.split(' ').map(y => parseInt(y)) : parseInt(x)).forEach((z, i) => {
    !i ? N = z : H = z
})

var cnt = 0


const giveWater = (H, cnt) => {
    const maxNum = Math.max.apply(null, H);
    const maxNumPos = []
    for (var i = 0; i < H.length; i++) {
        if (H[i] === maxNum) {
            if (i === 0 || H[i] !== H[i - 1]) {
                cnt++
            }
            maxNumPos.push(i)
        }
    }
    maxNumPos.forEach(x => H[x]--)
    if (H.filter(x => x === 0).length === H.length) {
        console.log(cnt)
    } else {
        giveWater(H, cnt)
    }
}

giveWater(H, cnt)