n = gets.to_i
r0 = gets.to_i
min = r0
r0 = gets.to_i
max = r0
dmax = max - min
(n-2).times{
  r = gets.to_i
  if max < r then
    max = r
    if dmax < max - min then
      dmax = max - min
    end
  end
  if min > r then
    max = r
    min = r
  end
}

printf "%d\n", dmax