import scala.io.StdIn.readInt

object Main extends App {
  val N = readInt()
  val ls = for (_ <- 0 until N) yield {
    readInt
  }
  var maxv = -2000000000
  var minv = ls.head

  for (i <- 1 until N) {
    maxv = scala.math.max(maxv, ls(i) - minv)
    minv = scala.math.min(minv, ls(i))
  }

  println(maxv)
}
