import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    var maxProfit = Long.MIN_VALUE
    var minR = scanner.nextLong()
    (2..n).forEach {
        val R = scanner.nextLong()
        maxProfit = Math.max(maxProfit, R - minR)
        minR = Math.min(minR, R)
    }
    println(maxProfit)
}
