object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)

    val n = scanner.nextInt
    val r = Seq.fill(n)(scanner.nextInt)

    var minR = r(0)
    var maxVal = Int.MinValue
    for(i <- 1 until n) {
      if(r(i) - minR > maxVal) maxVal = r(i) - minR
      if(r(i) < minR) minR = r(i)
    }
    println(maxVal)
  }
}

