import java.util.Scanner



object Main extends App {

  def read(): Array[Int] = {
    val sc: Scanner = new Scanner(System.in)
    val n = sc.nextInt
    val arr = Array.fill(n)(sc.nextInt)
    sc.close()
    arr
  }

  def solve()  = {
    val arr = read()
    var max = Long.MinValue
    var min = arr.head
    for(i <- 1 until arr.length) {
      max = Math.max(max, arr(i)-min)
      min = Math.min(min, arr(i))
    }
    max
  }
  println(solve)

}

