n = gets.to_i
arr = gets.split(' ').map(&:to_i)

current_height = 0
sum = 0

arr.each do |height|
  if current_height > height
    sum += current_height - height
  else
    current_height = height
  end
end

puts current_height.to_s