n = gets.chomp.to_i
ar = []
n.times do |num|
  ar << gets.chomp.to_i
end
m = 10000000000000000
d = -10000000000000000000000000
ar.each do |i|
  n = i.to_i
  a = n - m 
  d = a if a > d
  m = n if m > n 
end
p d