import scala.io.Source

object Main extends App {
  val lines = Source.stdin.getLines()
  val n     = lines.next().toInt

  val result: (Int, Int) =
    lines.toStream
      .take(n)
      .map(_.toInt)
      .foldLeft((Integer.MIN_VALUE, Integer.MAX_VALUE)) { (s, a) =>
        (Math.max(s._1, a - s._2), Math.min(s._2, a))
      }

  println(result._1)
}

