import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val r = Iterator.continually(io.StdIn.readInt()).take(n).toSeq
    val (_, mins) = r.foldLeft((Int.MaxValue, mutable.ListBuffer.empty[Int])) { case ((min, z), ri) =>
      z += min
      (Math.min(min, ri), z)
    }

    println(r.tail.zip(mins.tail).map { case (i, min) => i - min }.max)
  }
}