n = gets.chomp.to_i
h = gets.chomp.split(" ").map(&:to_i)
i, count = 0, 0

while true
  if h[i] > 0
    count += 1
    j = i
    while true
      if h[j] > 0
        h[j] -= 1
        if j < n - 1
          j += 1
        else
          break
        end        
      else
        break
      end
    end
  else
    i += 1
    if i == n
      break
    end
  end  
end
puts count

