import scala.io.StdIn.readLine

object Main{
  def main(args : Array[String]): Unit ={
    val n : Int = readLine().toInt
    val Hs : Array[Int] = readLine().split(' ').map(_.toInt)
    val solve = new Solve(n, Hs)
    solve.doSolve()
  }
}

class Solve(private val n : Int, private val Hs : Array[Int]){
  def getMin(hd : Int, tl : Int): (Int, Int) = {
    var res : Int = Int.MaxValue
    var position : Int = -1
    for(i <- hd to tl if Hs(i) < res){
      res = Hs(i)
      position = i
    }
    (res, position)
  }
  def conq(hd : Int, tl : Int): Int ={
    if(hd > tl) 0
    else if(hd == tl) Hs(hd)
    else{
      val (here_min, position) = getMin(hd, tl)
      for(i <- hd to tl) Hs(i) -= here_min
      here_min + conq(hd, position - 1) + conq(position + 1, tl)
    }
  }
  def doSolve(): Unit ={
    println(conq(0, n - 1))
  }
}