object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val H = Array.fill(N)(sc.nextInt())

    def solve(): Int = {
      var count = 0
      while (true) {
        var i = 0
        var flag = false
        while (i < N && H(i) == 0) {
          i += 1
        }
        while (i < N) {
          while (i < N && H(i) > 0) {
            H(i) -= 1
            i += 1
            flag = true
          }
          count += 1
          while (i < N && H(i) == 0) {
            i += 1
          }
        }
        if (!flag)
          return count
      }
      count
    }

    println(solve())
  }

}