n = gets.to_i
min = gets.to_i
max = gets.to_i - min
n -= 2
n.times do |i|
  now = gets.to_i
  prof = now - min
  if now < min then
    min = now
  end
  if max < prof then
    max = prof
  end
end
puts max