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