n = gets.chomp.to_i
h = gets.chomp.split
for i in 0..n
  h[i] = h[i].to_i
end
cnt = 0
id = 0

while true
  if h[id] != 0
    h[id] -= 1
  else
    tmp = id
    while id < n - 1
      if h[id + 1] == 0
        id += 1
      else
        break
      end
    end
    if tmp != 0
      cnt += 1
    end
  end
  
  if id == n - 1
    cnt += 1
    id = 0
  else
    id += 1
  end
  
  if0 = 0
  for i in 0..(n - 1)
    if h[i] != 0
      if0 += 1
      break
    end
  end
  if if0 == 0
    puts cnt
    break
  end
end