def main(input = STDIN)
  min, benefit = 1.0 / 0.0, -1.0 / 0.0
  input.gets.to_i.times do
    i = input.gets.to_i
    benefit = i - min if benefit < i - min
    min = i if min > i
  end
  puts benefit
end
main