import scala.io.StdIn.readInt

object Main extends App {
  var maxProfit: Int = Integer.MIN_VALUE
  val n = readInt()
  var minValue = readInt()
  for (_ <- 2 to n) {
    val current = readInt()
    maxProfit = Math.max(maxProfit, current - minValue)
    minValue = Math.min(minValue, current)
  }
  println(maxProfit)
}

