n = gets.chomp.to_i
a = []
n.times do
  a.push(gets.chomp.to_i)
end

max_gap = -Float::INFINITY
low = a[0]

for i in 1..a.size-1
  if a[i] - low > max_gap
    max_gap = a[i] - low
  elsif a[i] < low
    low = a[i]
  end
end

puts max_gap