n = gets.to_i
goal = gets.split.map(&:to_i)
now  = Array.new(n, 0)
count = 0

for left in 0 .. n - 1
  while now[left] < goal[left]
    x = left
    while now[x] < goal[x]
      now[x] += 1
      if x < n - 1
        x += 1
      else
        break
      end
    end
    count  += 1
  end
end

puts count
