# frozen_string_literal: true

n = gets.to_i
rate = n.times.map { gets.to_i }
# max_{j>i} (R_j-R_i) = max_i (max_{j>i} (R_j) - R_i)
max_later = Array.new(n - 1, 0)
max_later[n - 2] = rate[n - 1]
(n - 3).downto(0) do |i|
  max_later[i] = [max_later[i + 1], rate[i + 1]].max
end
puts((0...(n - 1)).map { |i| max_later[i] - rate[i] } .max)

