object Main
  extends App {
  val n                = readInt
  val source: Seq[Int] = Stream.continually(readInt).take(n)

  val answer = source.foldLeft((Integer.MAX_VALUE, Integer.MIN_VALUE))((acc, h) => (math.min(h, acc._1), math.max(acc._2, h - acc._1)))
  println(answer._2)
}
