import java.util.Scanner
import scala.annotation.tailrec

object Main{
  def main(args: Array[String]){
    val sc = new Scanner(System.in)
    val n = sc.nextInt
    val list = List.fill(n)(sc.nextInt)

    println(rec(list, Int.MinValue, Int.MaxValue))
  }

  @tailrec
  def rec(list: List[Int], preMax: Int, preMin: Int): Int ={
    if(list.length == 1) preMax
    else{
      val min = Math.min(preMin, list.init.min)
      rec(list.init, Math.max(list.last - min, preMax), min)
    }
  }
}