n = gets.to_i
a = $<.map(&:to_i).sort.reverse

def f(a, select, max)
	return if max >= $best
	if a.empty?
		$best = max if max < $best
		return
	end
	
	k = a[0]
	[k, select.size].min.downto(1){|r|
		(1..max).to_a.combination(r){|b|
			if check(select, b)			
				f(a[1..-1], select + [b + (max+1..max+k-r).to_a], max+k-r)
			end
		}
	}
	f(a[1..-1], select + [(max+1..max+k).to_a], max+k)
end

def check(select, a)
	select.all?{|b| (b & a).size <= 1}
end

s = 0
(0..n-1).each{|i|
	if a[i] > n-1
		s += a[i]-n+1
		a[i] = n-1
	end
}

$best = Float::INFINITY
f(a, [], 0)
p s + $best