n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

v = [0] * n
ans = 0
for i in 0...n
  while v[i] < a[i]
    ans += 1
    it = i
    while it<n && v[it] < a[it]
      v[it] += 1
      it += 1
    end
  end
end
puts ans