n = gets.to_i
rs = readlines.take(n).map(&:to_i)

_, max_profit = rs.drop(1).reduce([rs[0], -(10 ** 9)]) do |(min_r, max_profit), r|
  max_profit = [max_profit, r - min_r].max
  min_r = r if r < min_r
  [min_r, max_profit]
end

puts max_profit