import scala.io.Source

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


  def solve(list: Iterator[String]): String = {
    list.toStream
      .take(n)
      .map(_.toInt)
      .foldLeft((Int.MinValue.toInt, Int.MaxValue.toInt)) { case ((temporaryMax, temporaryMin), current) =>
        (temporaryMax max current - temporaryMin, temporaryMin min current)
      }._1.toString
  }
}


