let rec read max min = function
    0 -> max
  | i ->
     let n = read_int () in
     let (x, y) =
       if max < n - min then
         if 0 > n - min then (n - min, n) else (n - min, min)
       else
         if min > n then (max, n) else (max, min)
     in read x y (i-1)
;;

let () =
  let n = read_int () and
      r0 = read_int () and
      r1 = read_int ()
  in
  let init_max = r1-r0 and
      init_min = if r1 > r0 then r0 else r1
  in
  read init_max init_min (n-2) |> Printf.printf "%d\n";;