import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val h = (1..n).map { sc.nextInt() }


  val array = h.toIntArray()
  var count = 0
  for (i in 0 until n) {
    while (array[i] > 0) {
      count++
      for (j in i until n) {
        if (array[j] == 0) break
        array[j] -= 1
      }
    }
  }

  println(count)

}