let calc (l, s) = function
  | x when x > l && x < s -> (x, x)
  | x when x > l -> (x, s)
  | x when x < s -> (l, x)
  | _ -> (l, s)

let () =
  let n = read_int () in
  let li = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x)) in
  (* let () = Array.iter (Printf.printf "%d ") li in *)
  let l, s = Array.fold_left calc (1, 1000000000) li in
  print_int (l - s) ;
  print_newline ()
