let () =
  let n = read_int () in
  let minv = ref (read_int ()) in
  let maxv = ref min_int in
  for i = 1 to n - 1 do
    let j = read_int () in
    maxv := max !maxv (j - !minv);
    minv := min !minv j
  done;
  print_int !maxv; print_newline ()