fun main(args: Array<String>) {
    val 行数 = readLine()!!.toInt()
    val riList = mutableListOf<Double>()

    repeat((0 until 行数).count()) {
        riList.add(readLine()!!.toDouble())
    }
    var minv = riList[0]
    var maxv = Math.pow(10.0, 9.0) * -1.0
    for( j in 1 until 行数) {
        maxv = Math.max(maxv, riList[j] - minv)
        minv = Math.min(minv, riList[j])
    }
    println(maxv.toInt())
}
