n = gets.chomp.to_i

m = -Float::INFINITY
bottom = Float::INFINITY
for i in 1..n do
  num = gets.chomp.to_i
  if num - bottom > m
    m = num-bottom
  end
  if bottom > num
    bottom = num
  end
end
printf("%d\n",m)
