object D extends App {
  import java.{ util => ju }
  import scala.annotation._
  import scala.collection._
  import scala.collection.{ mutable => mu }
  import scala.collection.JavaConverters._
  import scala.math._
  import scala.io.StdIn.readLine

  val sc = new ju.Scanner(System.in)

  val n = sc.nextInt()
  val nums = Array.fill(n)(sc.nextInt())

  var maxV = nums(1) - nums(0)
  var minV = Integer.MAX_VALUE

  for (s <- nums) {
    maxV = max(maxV, s - minV)
    minV = min(minV, s)
  }
  println(maxV)
}