import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
  	val N = sc.nextInt()
  	val H = IntArray(N){0}
  	for (i in 0 until N) {
  	    H[i] = sc.nextInt()
    }
    var ans = 0
    val list = mutableListOf(H.toMutableList())
    while (list.size>0) {
        var lis = list.removeAt(0)
        val min = lis.min()!!
        ans += min
        for (i in 0 until lis.size) lis[i] -= min
        while (lis.size > 0) {
            val id = lis.indexOf(0)
            if (id == -1) {
                list.add(lis)
                break
            }
            id is Int
            if (id != 0) {
                list.add(lis.subList(0,id))
            }
            lis = lis.drop(id+1).toMutableList()
        }
    }
    println(ans)
}