fun main(args: Array<String>) {
    var list: MutableList<Int> = mutableListOf()
    val n = readLine()!!.toInt()
    var count = 0
    while (count < n) {
        list.add(readLine()!!.toInt())
        count++
    }
    var min = list.get(0)
    var max = -2147483648
    for (i in 0 until n - 1) {
        min = Math.min(min, list.get(i))
        max = Math.max(max, list.get(i + 1) - min)
    }
    println(max)
}
