import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val rs = BufferedReader(InputStreamReader(System.`in`))
            .readText()
            .trim()
            .split(regex = """\s+""".toRegex())
            .map { it.toInt() }
            .drop(n = 1)
            .toIntArray()

    // If we have `scan`, we can do better

    var maxR = Int.MIN_VALUE
    var minR = rs[0]

    for (r in rs.slice(1 until rs.size)) {
        maxR = Math.max(maxR, r - minR)
        minR = Math.min(minR, r)
    }

    println(maxR)
}
