fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val array = (1..n).map {
        readLine()!!.toInt()
    }

    var min = array[0]
    var max = array[1] - min
    array.forEachIndexed { index, num ->
        if (index == 0) return@forEachIndexed
        if (max < (num - min)) max = num - min
        if (min > num) {
            min = num
        }
    }
    println(max)
}
