arr = []
ARGF.each_line do |line|
    arr.push line.to_i
end
n = arr.shift
j = 1
min_val = arr[0]
result = arr[1]-arr[0]
while j < n
    val = arr[j] - min_val
    if result < val
        result = val
    end
    if arr[j] < min_val
        min_val = arr[j]
    end
    j += 1
end

puts result
