object Main extends App {
  val n = io.StdIn.readLine().toInt
  var arr = io.StdIn.readLine().split(" ").map(_.toInt)
  var count = 0
  while (arr.sum != 0) {
    count += arr.foldLeft((0, true))((acc, a) => {
      if (acc._2 && a != 0) (acc._1 + 1, false)
      else if (a == 0) (acc._1, true)
      else acc
    })._1
    arr = arr.map(x => if (x != 0) x - 1 else 0)
  }
  println(count)
}