n = gets.chomp.to_i
in_num = []
n.times do |num|
  in_num << gets.chomp.to_i
end
min_num = 10_000_000
diff = -10000000000000000000
in_num.each do |i|
  num = i.to_i
  a = num - min_num 
  diff = a if a > diff
  min_num = num if min_num > num 
end
puts diff