import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine.toInt
    val _input = new Array[Int](n)
    1 to n foreach { i =>
      _input(i-1) = readLine.toInt
    }
    val input = _input.toList
    // println(input)

    println(calMaxProf(input))
  }

  @tailrec def calMaxProf(input: List[Int], maxProf: Int = Int.MinValue): Int = input match {
    case head :: Nil =>
      maxProf
    case head :: tail =>
      val prof = tail.map(_ - head).max
      if (prof > maxProf) {
        calMaxProf(tail, prof)
      } else {
        calMaxProf(tail, maxProf)
      }
    case Nil =>
      maxProf
  }
}

