n = gets.to_i
r = []
n.times {r << gets.to_i}

min_r = r[0]
max = -Float::INFINITY
(n - 1).times do |i|
  a = r[i + 1]
  dif = a - min_r
  max = dif if dif > max
  min_r = a if a < min_r
end
puts max
