open Printf
open Scanf
let num = scanf "%d " (fun x -> x);;

let () =
	let rec f n min max = 
	  match n with
	    0 -> (max - min)
	    | t -> let x = scanf "%d " (fun y -> y) in
	    	if x <= min then (f (t-1) x x) else (
	    		if x >= max then f (t-1) min x else (f (t-1) min max) )
	in printf "%d\n" (f num max_int 0);;