n = gets(chomp:true).to_i

r = []
n.times do
  r << gets(chomp:true).to_i
end

maxv = r[1] - r[0]

minv = r[0]

for j in 1...n
  if maxv < r[j]-minv
    maxv = r[j]-minv
  end

  minv = r[j] if minv > r[j]

end

puts maxv
