object Main {
    def main(args: Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        val hs = List.fill(n)(sc.nextInt)
        val hs_max = hs.max
        var ans = 0
        var tmp = -1
        for (h <- 1 to hs_max) {
            for(i <- 0 until n) {
                if (hs(i) - h >= 0) {
                    if (tmp == -1) {
                        ans += 1
                        tmp = 1
                    }
                } else
                    tmp = -1
            }
            tmp = -1
        }
        println(ans)
    }
}