import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine().map(_.toInt)
    val hs = readLine().split(" ").map(_.toInt)

    var ans = 0
    hs.foldLeft(0)((a, b) => {
      if (b > a) ans += b - a
      b
    })
    println(ans)
  }
}
