import scala.io.StdIn.readInt

object Main extends App {
  val n = readInt
  val m = for(i <- 0 until n) yield readInt
  var maxv = m(1)-m(0)
  var minv = if(m(0)>m(1)) m(1) else m(0)

  for(i<-m.drop(2)) {
    if(i-minv > maxv && maxv >= 0)
      maxv = i-minv
    else if(i-minv > maxv) {
      maxv = i-minv
      minv = i
    }
    else( i-minv < 0 )
      minv = i
  }
  println(maxv)
}