import scala.io.StdIn
import scala.annotation.tailrec

object Main{
  def main(args: Array[String]){
    val n = StdIn.readInt
    val inputs = (0 to n-1).map(_ => StdIn.readInt).toVector

    @tailrec
    def loop(vec: Vector[Int],  max: Int): Int = {
      if(vec.length == 1) max
      else {
        val vecInit = vec.init
        loop(vecInit, Math.max(vec.last - vecInit.min,  max))
      }
    }

    println(loop(inputs,  Int.MinValue))
  }

}