let () =
  let n = read_int () in
  let min = ref 0 in
  let ans = ref (-1000000001) in
  let rec read i =
    if i > n then !ans
    else begin
      let r = read_int () in
      if i = 1 then min := r
      else begin
        if !ans < r - !min then ans := r - !min;
        if !min > r then min := r;
      end;
      read (i + 1)
    end
  in
  Printf.printf "%d\n" (read 1)