import scala.io.StdIn._

object Main extends App {
  val n = readLine.toInt
  val nums = (1 to n).map(_ => readLine.toInt)
  var diff_v = Int.MinValue
  var min_v = nums(0)
  
  nums.drop(1).foreach(x => {
    diff_v = if (x - min_v > diff_v) x - min_v else diff_v
    min_v = if (x < min_v) x else min_v
  })
  println(diff_v)
}
