object Main {
    def main(args: Array[String]) = {
        val in = io.Source.stdin.getLines.map(_.toInt).toList.tail
        println(in.foldLeft((Int.MaxValue, Int.MinValue)){case ((m, d), r) => (m min r, d max (r - m))}._2)
    }
}