
import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    val n = readInt
    var min = Int.MaxValue
    var max = Int.MinValue
    for (i <- 0 until n) {
      val value = readInt
      if (value - min > max ) max = value - min
      if (value < min) min = value
    }
    println(max)
  }
}

