import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val n = input.nextLine().toInt
      val rs = Iterator.continually(input.nextLine().toInt).take(n)

      var min = Integer.MAX_VALUE
      var max = Integer.MIN_VALUE
      var maxDiff = Integer.MIN_VALUE
      rs.foreach { r =>
        val diff = r - min
        if (diff > maxDiff){
          maxDiff = diff
        }

        if (r < min) {
          min = r
        }
      }

      output.println(maxDiff)
    }

  }

}

