n = gets.chop.to_i
R = []

n.times { R << gets.to_i }

maxv = -2000000000
minv = R[0]

def maxof(x, y)
    return (x > y) ? x : y
end

def minof(x, y)
    return (x < y) ? x : y
end

(1...n).each do |i|
  maxv = maxof(maxv, R[i] - minv)
  minv = minof(minv, R[i])
end

puts maxv

