import scala.io.StdIn.readInt
object Main {
    def main(args: Array[String]): Unit = {
        val len = readInt
        val list = (1 to len).toList.map(x => readInt)
        println(maximumProfit(list)._2)
    }
    
    def maximumProfit(list: List[Int]): (Int, Int) = {
        def go(list: List[Int], min: Int, maxDiff: Int): (Int, Int) = list match {
            case x :: xs if x < min && (x - min) > maxDiff => go(xs, x, x - min)
            case x :: xs if x < min => go(xs, x, maxDiff)
            case x :: xs if (x - min) > maxDiff => go(xs, min, x - min)
            case x :: xs => go(xs, min, maxDiff)
            case _ => (min, maxDiff)
        }
        list match {case x :: xs => xs match { case y :: ys => go(xs, x, y - x) }}
    }
}
