n = gets.to_i
r0 = gets.to_i
min = r0
max = r0
diff = - 10**9
(n - 1).times do
  r = gets.to_i
  if min >= r
    diff = [diff, r - min].max
    min = r
    max = r
  elsif max < r
    diff = [diff, r - min].max
    max = r
  end
end
puts diff

