val n = readLine.toInt
val input = (1 to n map { _ => readLine.toInt }).toList
// println(input)

def calMaxProf(input: List[Int], maxProf: Int = -200000): Int = input match {
  case head :: Nil =>
    maxProf
  case head :: tail =>
    val prof = tail.map(_ - head).max
    if (prof > maxProf) {
      calMaxProf(tail, prof)
    } else {
      calMaxProf(tail, maxProf)
    }
  case Nil =>
    maxProf
}

println(calMaxProf(input))
