import scala.io.StdIn.readInt

object Main extends App {
  val n = readInt
  var minv = readInt
  var maxv = Int.MinValue
  var i=1

  while(i<n) {
    val r = readInt
    val m = r-minv

    if(m > maxv) maxv = m
    if(m < 0) minv = r
    i += 1
  }
  println(maxv)
}