let () =
  let n = read_int () in
  let ans = ref min_int in
  let m = ref (read_int ()) in
  for _ = 1 to n - 1 do
    let r = read_int () in
    if !ans < (r - !m) then ans := r - !m;
    if r < !m then m := r;
  done;
  Printf.printf "%d\n" !ans