object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val r = Iterator.continually(io.StdIn.readInt()).take(n).toList
    println(maximumProfit(r))
  }

  def maximumProfit(r: List[Int]): Int = {
    @annotation.tailrec
    def maximum(min: Int, max: Int, r: List[Int]): Int = r match {
      case Nil => max
      case h :: t => maximum(Math.min(min, h), Math.max(max, h - min), t)
    }

    maximum(r.head, Int.MinValue, r.tail)
  }
}