import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  def nextInt() = sc.next.toInt

  val n = nextInt
  val rs = List.fill(n)(nextInt)


  var profits = List[Int]()

  def loop(xs: List[Int]): Unit = {
    if (xs.tail ne Nil) {
      profits = xs.tail.max - xs.head :: profits
      loop(xs.tail)
    }
  }
  loop(rs)
  println(profits.max)
}

