fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val list = readLine()!!.split(" ").map { it.toInt() }
    var f = list[0]
    var res = 0
    for (i in list) {
        if (i >= f) {
            res += i - f
            f = i
        } else {
            f = i
        }
    }
    println(res)
}