fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val xs = (0 until n).map {
        readLine()!!.toInt()
    }
    var x = xs[0]
    var ans = Int.MIN_VALUE
    for (i in 1 until n) {
        ans = maxOf(ans, xs[i] - x)
        x = minOf(x, xs[i])
    }
    println(ans)
}
