fun main(args: Array<String>) {
    val n = readLine()?.toInt()?: return
    val aList = readLine()?.split(" ")?: return
    var prev = 0
    aList.forEachIndexed { index, item ->
        if (aList.count() != index+1) {
            if (item < aList[index+1]) {
                prev = aList[index+1].toInt() - item.toInt()
            }
        }
    }
    println(prev)
}