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

    val n = scanner.nextInt
    var maxVal = Int.MinValue
    var minR = scanner.nextInt
    for(_ <- 2 to n) {
      val r = scanner.nextInt
      if(r - minR > maxVal) maxVal = r - minR
      if(r < minR) minR = r
    }
    println(maxVal)
  }
}

