n = gets.to_i
a = gets.split.map(&:to_i)

hash = {0 => 0}

a.each do |w|
    new_hash = Hash.new(-Float::INFINITY)
    hash.each do |l, cost|
        new_hash[l] = cost if cost > new_hash[l]
        if l < w
            new_hash[w] = cost + w if cost + w > new_hash[w]
        end
    end
    hash = new_hash
end
p (1 + n) * n / 2 - hash.values.max