import scala.io.StdIn.readInt
  
object Main extends App {
  val (x,minv) = (readInt, readInt)

  val m = (1 until x).map(_=>readInt).foldLeft((minv,Int.MinValue)) { (x, r) =>
      (r.min(x._1), (r-x._1).max(x._2))
    }._2
  println(m)

}
