input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
N = lines.shift() * 1
l = lines.shift().split(' ')
max = 0
for (i=0; i<N; i++) {
    l[i] = l[i] * 1
    if (max < l[i]) {
        max = l[i]
    }
}

cnt = 0
for (i = 1; i<=max; i++) {
    t = 0
    f = 1
    for (j = 0; j < N; j++) {
        if (f == 1) {
            if (l[j] >= i) {
                t++
                f = 0
            }
        } else {
            if (l[j] < i) {
                f = 1
            }
        }
    }
    if (t === 0) {
        t = 1
    }
    cnt += t
}
console.log(cnt)