'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')
  const N = Number(input[0])
  const h = input[1].split(' ').map(n => Number(n))
  let i = 0
  let ans = 0
  while (true) {
    for (let j = i; j < h.length && h[j] > 0; j++) {
      h[j]--
    }
    let total = h.reduce((p, c) => {
      return p + c
    })
    ans++

    if (total <= 0) {
      break
    }
    while (h[i] <= 0) {
      i++
    }
  }
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
