n = gets.chomp.to_i
a = []
n.times do |i|
  a[i] = gets.chomp.to_i
end
min = a[-1]
mjmax = a[-1]
max = a[-1]
maxka= -9999999
ans = -999999999
dans = 0
a.reverse!
n.times do |i|
d = a[i]
  if(d > max)
  maxka = max - d
  if(ans < maxka)
    ans = maxka 
  end
  max = d
  min = d
  elsif(d <= min and i != (0))
  min = d
  maxka = max - min
      if(ans < maxka)
  ans = maxka 
      end
  end 
end
puts ans