import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val array = IntArray(n){sc.nextInt()}
    var min = array.first()
    var max = array[1] - array[0]
    (1 until n).forEach {
        max = maxOf(max, array[it] - min)
        min = minOf(min, array[it])
    }
    println(max)
}
