n  = gets.strip.to_i
xs = gets.strip.split.map(&:to_i)

w = []
count = 0
for i in 0...xs.max
  prev = 0
  for j in 0...n
    if xs[j] > 0 then
      xs[j] -= 1
      count += 1 if prev == 0
      prev = 1
    else
      prev = 0
    end
  end
end
puts count