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

    val max = list.max
    val maxi = list.indexOf(max)
    val min = list.min
    val mini = list.indexOf(min)
    if(mini <= maxi) {
        println(max-min)
        return
    }

    var ret = Int.MinValue
    for (i <- 0 until list.length-1) {
        var maxv = Int.MinValue
        (i+1???to list.length).foreach(if(_>maxv)maxv=_)
        val t = maxv - list(i)
        if(t>ret) ret = t
    }
 
    println(ret)
  }
}