n = gets.to_i
r = Array.new
 
r0 = gets.to_i
r1 = gets.to_i
max_r = r1 - r0
min_v = r0 < r1 ? r0 : r1
 
(n-2).times do
    r = gets.to_i
    current = r - min_v
    max_r = current if current > max_r
    min_v = r if r < min_v
end
  
puts max_r