import java.util.Scanner

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

    var minv = r(0)
    var maxv = r(1) - r(0)

    (1 until n).foreach { j =>
      maxv = Math.max(maxv, r(j) - minv)
      minv = Math.min(minv, r(j))
    }

    println(maxv)
  }

}

