fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var maxProfit = -2000000000 // 十分小さい値
    var minValue = readLine()!!.toInt()

    for (i in 0 until n - 1) {
        val value = readLine()!!.toInt()
        maxProfit = when {
            maxProfit < value - minValue -> value - minValue
            else -> maxProfit
        }
        minValue = when {
            minValue < value -> minValue
            else -> value
        }
    }
    println(maxProfit)
}
