n = gets.to_i
h = gets.split.map(&:to_i)
ans = 0
f = true
while f
  f = false
  m = true
  0.upto(n - 1) do |i|
    if h[i] > 0
      h[i] -= 1
      ans += 1 if m
      f = true
      m = false
    else
      m = true
    end
  end
end
puts ans