import scala.io.Source

object Main {
  def calcMaxProfit(numbers: Seq[Int]): Int = {
    if (numbers.size == 2) {
      numbers(1) - numbers(0)
    } else {
      val maxProfit: Int = (1 to numbers.size-2)
        .map{i =>
          val as = numbers.take(i)
          val bs = numbers.drop(i)
          bs.max - as.last
        }
        .max
      maxProfit
    }
  }

  def main(args: Array[String]): Unit = {
    // Get interator of stdin
    val stdinIterator = Source.stdin.getLines()

    // Skip the first line
    stdinIterator.next()

    // Get input
    val numbers: Seq[Int] = stdinIterator.toSeq.map(_.toInt)

    // Calc max profit
    val maxProfit = calcMaxProfit(numbers)

    // Print max profit
    println(maxProfit)
  }
}
