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)

    var ret = Int.MinValue
    for (i <- 0 until list.length) {
        val t = list.slice(i+1,list.length).max - list(i)
        if(t>ret) ret = t
    }

    println(ret)
  }
}