n = gets.chop.to_i
h = gets.chop.split.map(&:to_i)


f = []

n.times do
  f << 0
end


ans = 0

tmp_arr = []

index = 0


while 1 do

  #これはok
  if h == f then
    break
  end

  for i in 0..n-1 do
    if h[i] != f[i]  then
      tmp_arr << i
    end

    if h[i] == f[i] || i == n-1 then

      if !tmp_arr.empty?
        ans +=1
      end

      for tmp in tmp_arr do
        f[tmp] += 1
      end

      tmp_arr = []

    end

  end
end


puts ans
