n = gets.chomp.to_i

m = -Float::INFINITY
num = gets.chomp.to_i
bottom = num
for i in 2..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)
