def aa
    n = gets.chomp.to_i

    r = []
    for i in 1..n
        r.push(gets.chomp.to_i)
    end

    ma = -1000000000
    mi = r[0]
    for j in 1..(n-1)
        ma = [ma, r[j]-mi].max
        mi = [mi, r[j]].min
    end

    puts ma
end

aa
