# frozen_string_literal: true
n = gets.to_i
min, diff = gets.to_i, Float::Infinity
(n - 1).times do
  r = gets.to_i
  if r - min > diff
    diff = r - min
  end
  if r < min
    min = r
  end
end
puts diff

