import java.util.*

fun main(vararg args: String) {
    val scanner = Scanner(System.`in`)
    val size = scanner.nextInt()

    val list = mutableListOf<Int>()
    for (i in 1..size) {
        list.add(scanner.nextInt())
    }

    val max = list.max() ?: throw IllegalArgumentException()
    var shouldFill = false
    var count = 0

    for (i in 1 .. max) {
        list.forEach {
            val result = it - i
            if (result >= 0 && !shouldFill) {
                shouldFill = true
                count += 1
            } else if (result < 0) {
                shouldFill = false
            }
        }
        shouldFill = false
    }

    println(count)
}