import scala.io.StdIn.readInt

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

  for(i<-1 until n) {
    val r = readInt
    val m = r-minv

    if(m > maxv) {
      maxv = m
      if(m < 0) minv = r
    }
    else if(m < 0) minv = r
  }
  println(maxv)
}