N = gets.to_i
hs = gets.chomp.split.map(&:to_i)

def segments(hs, h)
  e, s = false, 0
  N.times { |i|
    if hs[i] >= h && !e
      s += 1
      e = true
    end
    e = false if hs[i] < h && e
  }
  s
end

ans = 0
hs.max.times { |i|
  ans += segments(hs, i + 1)
}
p ans