fun main(args: Array<String>) {
  val N = readLine()!!.toInt()
  val r = (0 until N).map { readLine()!!.toLong() }

  var min = r[0]
  var profit = -1000000000L
  (1 until N).forEach { i ->
    min = Math.min(min, r[i-1]) 
    profit = Math.max(profit, r[i] - min)
  }  

  println(profit)
}
