object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    def reduce(h: Array[Int]): Int = {
      var count = 0
      var previousWatered = false
      for { i <- h.indices } {
        if (h(i) != 0) {
          if (!previousWatered) count += 1
          h(i) -= 1
          previousWatered = true
        } else {
          previousWatered = false
        }
      }
      count
    }

    val N = sc.nextLine().toInt
    val h = readLineInts
    var count = 0
    while (true) {
      val next = reduce(h)
      if (next == 0) return println(count)
      count += next
    }
  }
}