
n = STDIN.gets.to_i

min = Float::INFINITY
diff = -Float::INFINITY

n.times do |i|
    num = STDIN.gets.to_i
    if num - min > diff
        diff = num - min
    end
    if num < min
        min = num
    end
end

puts diff